How to fix java.io.FileNotFoundException? - android

I try to access the file I had downloaded from flutter app and save it to external storage. I call the file and use it in java part but it show this error:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/abc.xyz.qwe/files/mobilenet.tflite
I have tried to grant permission before call the file but it still not work (The file is exist, i have checked).

You start the file name with a slash. What directory is the file located in? If the storage folder is not in the root directory (/), then you won't be able to find the file. If storage is in the same place as the java file you're running, you should remove the first /

Related

Android 11 - How to access android/data/an app directory

I want to access Chrome browser directory in android/data and then copy files(TXT) From assets to that folder
1.how to get permission In Android 11
2.after getting permission How to copy any file from asset folder to that directory
Please give me an code that works like this
Image First
Image Second
App link above screenshot: https://play.google.com/store/apps/details?id=eu.tsoml.graphicssettings
If your app holds REQUEST_INSTALL_PACKAGES permission it can access Android/obb directory.
and for more details

How to Save files to system files on Android

I want to save file to files system on Android to this path "/efs/wifi/"
I created My file by FileWriter writer =new FileWriter (file,true) i want save this file to path above
For root devices
Another thing how can i copy from sd card to same path above "efs/wifi/" Please help me .
You can use libsupersu to make application for root device.
Add dependency to your gradle file:
compile 'eu.chainfire:libsuperuser:1.0.0.+'
In your code, ask root permission by:
Shell.SU.available();
After your app grant permission from user, you can copy file to anywhere to want.

React-native-fs moveFile: ENOENT: no such file or directory, even though file exists

Using react native (0.44), react-native-fs (2.3.2) and react-native-zip. Trying to create a zip and then move it to another folder.
Expected:
Create zip file of files at source folder to target path
When success (promise resolves), move zip to another location
Actual:
Zip file creation succeeds:
Successfully created zip at /storage/emulated/0/Android/data/my_app/files/2017-06-07-14_09_39.zip
After zip creation promise resolves, check if source path exists:
fs.exists('/storage/emulated/0/Android/data/my_app/files/2017-06-07-14_09_39.zip')
-> true
But:
fs.moveFile('/storage/emulated/0/Android/data/my_app/files/2017-06-07-14_09_39.zip', targetPath)
-> Error: ENOENT: no such file or directory, open '/storage/emulated/0/Android/data/my_app/files/2017-06-07-14_09_39.zip'
Read and write permissions are OK in AndroidManifest etc.
Any ideas?
Check that "targetPath" includes both target directory path and target filename. Also check that the target directory exists.
One solution could be you forgot to add the filename so the destPath also, it's not enough to specify a directory.

Bad path trying to open file in Android

I'm trying to open a file with this:
document = builder.parse(new File("Data.xml"));
and I'm getting this message:
/Data.xml: open failed: ENOENT (No such file or directory)
and the file is in the root directory of the android project.
You are trying to open a file located in / (in linux this is the root directory of your file system). Instead you should be trying to create a file either on the SDCard or within the local storage directory for your application.
See this for more clarification: http://developer.android.com/guide/topics/data/data-storage.html
Move Data.xml into the assets folder of your project. Then to get a file reference, call getResources().getAssets().openFd( "Data.xml" )
You should probably try using a file input stream constructor for the builder instead, and use openFileInput( String fileName ) to get that, which does only use your app's data directory.
Using persistent storage
openFileInput()

How to copy a file from root of SD Card to one of its parent directory

Im having a file stored in the root of the SD card(i.e not inside any folder)..
but i need my file to be in data/local/ which is above the SD card..
my app is for root users..so i tried doing the following:
"cd "+Environment.getExternalStorageDirectory().getAbsolutePath().toString()
mv file ../
It changes directory to SD Card but doesnt move the file..with error: failed on 'file' - Cross-device link, 255
So i cant move between different mediums .. im guessing so..
Help appreicated.. thanks!
Use the File.renameTo() method in your code.
Edit:
Aha! but the documentation for this API says:
On Android, applications are most likely to hit this restriction when
attempting to copy between internal storage and an SD card.
Hmmm...
I guess you'd have to copy the file and then delete the original.

Categories

Resources