Read CSV File in android app - android

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.

Related

Load File on Android

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");

How to delete files in Android?

I have a file with this path:
file:/mnt/sdcard/Android/data/myapp/files/Pictures/IMG_20140108_160223.jpg
When I try this code:
File f = new File(path);
f.delete();
The file is not deleted.
How can I do?
I've found a similar question here:
How to delete a file from SD card?
The file: prefix seems unnecessary.
try/mnt/sdcard/Android/data/myapp/files/Pictures/IMG_20140108_160223.jpg
Also you have to give permission if you are using >1.6 SDK
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
in AndroidManifest.xml file
You may need to use
file.getCanonicalFile().delete();
or even (assumming this is a context)
this.deleteFile("string");
More Infos here to delete file with context object
You may also delete your file:/ at the beginning of your File object creation.

open assets or raw file as File

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");

Android SDcard Permissopn denied while writing a file?

In my application, while writing a file sdcard it shows Permission denied. But i give permission in sdcard. Please help?
Writing file code:
File sdcard = Environment.getExternalStorageDirectory();
File f = new File(sdcard, "/abc.txt");
if (f.exists()) {
f.delete();
}
Manifest :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Thanks in advance!!
You need add use-permission in AndroidManifest file, and you should better check if you can r/w the file use canWrite() canRead() before use it.
I think your SD card is currently connect to your computer so it will cause problem. I get in this situation before. You need to unmount sd card first
it requires permissions in manifest file, add this line to your manifest file
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Look at this Question Android saving file to external storage
in menifest file add permission to write file
pls try with file name as below
String filename="aa.txt";
String filepath= getFilesDir().getAbsolutePath();
File Filseting = new File(filepath, filename);

How to delete a file from an Android application

How can I delete a file from an Android application? Can I do it the same way I would for deleting a file in Java?
File file = new File(selectedFilePath);
boolean deleted = file.delete();
and set this permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in AndroidManifest.xml file
The Android Developer Homepage has a really good Dev Guide section.
Answer to your question:
Files can be deleted using: File.delete() method. (I found that by searching for "file delete" on the page above!)
But of course, there's much more to that: you need to understand how Android stores files and which files your application is allowed to modify! (basically only its own files, all the others are not accessible)
File file = new File(path);
return file.delete();

Categories

Resources