I want load a file wav from sdcard in my android project but I don't succeed.
I'm using
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/mnt/sdcard/.....wav");
but I get this error
java.io.FileNotFoundException: /mnt/sdcard/mnt/sdcard/......wav (No such file or directory)
Can you help me, please?
the first parameter is already the path - do not put /mnt/sdcard/ to the second parameter
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,".....wav");
Remove this /mnt/sdcard/ from the line It is already there in file
Replace this:
File file = new File(sdcard,"/mnt/sdcard/.....wav");
with this:
File file = new File(sdcard,".....wav");
Related
I know it should be a nonsense but I´m having some difficults to store a image in a custom folder. I know how to store them into the cache directory or in the camera folder, but I want to store them into a custom folder and I´m having an error. I´m using this code:
File folder = new File(Environment.DIRECTORY_DCIM + "/ExtremEye");
folder.mkdirs();
fos = new FileOutputStream(new File(folder, "FRAME_"+ nombre + ".png"));
But I´m getting this logcat:
File not found: /DCIM/ExtremEye/FRAME_20131101_120104.png: open failed: ENOENT (No such file or directory)
It´s a simple question, I know, but I have been trying different ways and I didn´t succeed.
Thanks for help!!
from the logcat seems that is trying to access DCIM in the root /, but it should be on the External storage. Try this way:
File folder = new File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_DCIM + "/ExtremEye");
Is there a way to open assets or raw resource as File ? I have method that needs open file as File but since i want store my file in assets or in raw folder i cannot access them.
I tried open it with file:///android_asset/filename.xml but received FileNotFound exception.
File file = new File("....");
x.load(file);
Is there a way to open assets or raw resource as File ?
No, sorry. They do not exist as files. You can only get an InputStream.
If you're willing to zip up the file first, you can do this:
File dir = getFilesDir();
IoUtils.extractZipResource(getResources().openRawResource(R.raw.texfilezip), dir, true);
File textFile = new File(dir, "textfile.txt");
I have a problem.
I use this code to read the content of a zip file:
File file = new File(TogglesManager.EXTERNAL_STORAGE_THEMES_DIRECTORY+"filename.zip");
ZipFile zip = new ZipFile(file);
But when I try to use an assets I have a FileNotFoundException.
To read asset zip file I use this code:
File file = c.getFileStreamPath("assetsFile.zip");
ZipFile zip = new ZipFile(file);
The "file" is not null, because if I write file.getName(); I see the correct file name.
I don't want to use ZipInputStream class, but only ZipFile
You cannot access Assets using normal file operations. You will have to use
AssetManager assetManager = mContext.getAssets();
InputStream is = assetManager.open("assetsFile.zip");
But since ZipFile does not take InputStream as a parameter, you will have to copy asset file onto internal storage and then use File
Further AFAIK, apk is zipped, so storing a zipped file inside assets might not change storage used by much, so maybe you donot need to use zipfile inside assets.
i want to access the /data/local/tmp for any random access file
(RAF) file how to get the path of that file?
go this way and read the raf file line by line but be assure that the folder have read permission to other user or you can change it from adb shell by using chmod commmand .....
File finalFile = new File("/data/local/tmp", fileName);
RandomAccessFile rafTemp = new RandomAccessFile(finalFile, "r");
For accessing the any file through code , you must know the path of the file.
and then you can use the code:
File finalFile = new File/t("/data/local/tmp", fileName);
RandomAccessFile rafTemp = new RandomAccessFile(finalFile, "r");
"/data/local/tmp" is the path for the file. It can differ file to file. So you must know the path of file before accessing it.
Thanks in advance,
How to read csv file from sdcard.
and how to give the permission of read/writer for file in android application.
thanks again.
This might be helpful to you
File dir = Environment.getExternalStorageDirectory();
File f = new File(dir, "path/dir1/sdcard.ext");
I don't know about the permissions but the above will certainly allow you to read the file from the sdcard in the path directory.