Cant read file name with Russian char from FileInputstream - android

I read some files from phone storage (which are in Russian name) i listed all files it will give me all file path correct but the time when i try to read from new FileInputStream(file) it gave me file not found exception i don't know why.
my code is like the following :
FileInputStream file1 = new FileInputStream(file); //this line gave error and file path is /storage/emulated/0/bhanuдосвидания.txt
and logcat is the following :
02-10 15:48:58.000: W/System.err(16013): java.io.FileNotFoundException: /storage/emulated/0/bhanuдосвидания.txt: open failed: ENOENT (No such file or directory) 02-10 15:48:58.020: W/System.err(16013): at libcore.io.IoBridge.open(IoBridge.java:409) 02-10 15:48:58.050: W/System.err(16013): at java.io.FileInputStream.<init>(FileInputStream.java:78) 02-10 15:48:58.050: W/System.err(16013): at com.S3Upload.UploadActivity$allCalculation.doInBackground(UploadActivity.java:16‌​71) 02-10 15:48:58.080: W/System.err(16013):
please help me...

May be the problem is like you change your file name to lower case. Try to remove lower case from your code and check.

please try to do something like the following :
BufferedReader in = new BufferedReader(
new InputStreamReader(
new FileInputStream(file), "UTF8"));

Related

Exifinterface saveAttributes() fail because of 'Failed to copy original file to temp file'

So now I'm writing custom camera, and I want to write location into images that I captured, for some reason I cannot use builder.set() here.
The file was created like this:
String name = System.currentTimeMillis() + ".jpg";
file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM + "/Camera"), name);
To make question simple, I just simply create an ExifInterface with a correct file path, and call saveAttributes() method,it looks like this:
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
exif.saveAttributes();
but then I get this log,
D/qdgralloc: GetYUVPlaneInfo: Invalid format passed: 0x21
D/MediaScannerConnection: Scanned /storage/emulated/0/DCIM/Camera/1619507958498.jpg to content://media/external_primary/images/media/11032
V/haha: Failed to copy original file to temp file
W/System.err: java.io.IOException: Failed to copy original file to temp file
at android.media.ExifInterface.saveAttributes(ExifInterface.java:2098)
at com.example.secondpractice.fragment.CameraFragment.takeDelayedPicture(CameraFragment.java:1042)
at com.example.secondpractice.fragment.CameraFragment.onClick(CameraFragment.java:1301)
at com.example.secondpractice.fragment.-$$Lambda$zncvcj43pAXOQyaoJTDWHHAg_tA.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7496)
at android.view.View.performClickInternal(View.java:7473)
at android.view.View.access$3600(View.java:831)
W/System.err: at android.view.View$PerformClick.run(View.java:28647)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:7876)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
W/System.err: Caused by: java.io.IOException: Couldn't rename to /storage/emulated/0/DCIM/Camera/1619507958498.jpg.tmp
at android.media.ExifInterface.saveAttributes(ExifInterface.java:2084)
... 14 more
I think problem happens here:Caused by: java.io.IOException:
Couldn't rename to /storage/emulated/0/DCIM/Camera/1619507958498.jpg.tmp
By the way, the getAttributes() works fine, only saveAttributes() has the problem
please help me to check how to solve this. Thanks a lot
On an Android 11 device the OS is very picky concerning extensions.
You can create .jpg, .png and .webp files in DCIM directory and maybe other image files.
But not .tmp files as they are no image files.
So you are victim of the ExifInterface programmers.
If they had decided for .jpg.jpg and not for .jpg.tmp you would not have this trouble.
File an issue/report.

FileInputStream can't read file in Android R

File file = new File(filePath);
InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);
simple piece of code.
i checked the following:
file!=null
file.isFile()
file.exists()
file.canRead()
everything is true. The program have the permission and can actually read this existing file, but put it in a FileInputStream, it throws the following exception:
java.io.FileNotFoundException: /storage/emulated/0/XNR/Setting.gson: open failed: EFAULT (Bad address)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
...
Caused by: android.system.ErrnoException: open failed: EFAULT (Bad address)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7372)
at libcore.io.IoBridge.open(IoBridge.java:478)
at java.io.FileInputStream.<init>(FileInputStream.java:159) 
... 
it works well only on a api 23 emulator now. maybe the issue is cause by some new mechanics of newer version android api?
funny thing is, i developed and tested it on a android r emulator exclusively 2 months ago and everything is fine, after tested on several actuall devices, the project was deemed done and finished, it sat in my hard drive untouched for 2 months, i can even see the same .gson file generated by it. almost looks like it just went bad on it's own.
Using getFilesDir() or getExternalFilesDir(String) to access storage instead of using Environment.getExternalStorageDirectory() solved the problem, android no longer supports that since q based on the comment above.

How to post audio file to server in android

I need to post Audio file(picking from Audio/* intent) to server.here i got Uri, but the posting param type is File. I Used below code but it shows /directory/.. is not a absolute path and getting FileNotFoundException. Any one suggest me..
Code :
Uri uri=data.getData();
File f=new File(uri.getPath());
Log:
09-26 21:20:19.735: I/System.out(920): java.io.FileNotFoundException: /document/audio:5257: open failed: ENOENT (No such file or directory)
(this is a duplicate)
See here:
Convert file: Uri to File in Android
Don't use Uri::ToString() and use Uri::getPath() instead.

csv FileNotFoundException: ENOENT

I am trying to access a csv file from the assets for my app and all I get is FileNotFoundException. I get the same when I try to access it from elsewhere. Any idea what I should be doing here?
Log messages work just fine until then. The error on the logcat is as follows.
Tag Text
System.err java.io.FileNotFoundException C:\Users.....\assets\cms.csv: open failed ENOENT (no such file or directory)
for the code:
br = new BufferedReader(new FileReader
("C:\\Users\\Srihari\\workspace\\CMSHealthcare\\assets\\cms.csv"));
Any help is appreciated!
Thanks in advance!
Dont point it to the file system on your computer...instead use the getAssets method to target the filesytem in the raw folder that gets bundled into your apk (the binary of the app)
br = new BufferedReader(new InputStreamReader(getAssets().open("cms.csv")));

java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)

I'm getting an error on the following line of code:
FileInputStream is = new FileInputStream("/sdcard/DCIM/ROBIN.jpg");
The error is:
java.io.FileNotFoundException: /sdcard/DCIM/ROBIN.jpg (No such file or directory)
But the image is present in the directory
My USB connection is Charge only
Never hardcode paths like /sdcard. For example, /sdcard is wrong on most Android devices. Use Environment.getExternalStorageDirectory() to find the root of external storage.
Make sure you have set the permission WRITE_EXTERNAL_STORAGE in your manifest.

Categories

Resources