File I/o Not Working
I am trying to test a simple file i/o program on android where i type in some text in EditText and when i click the Save Button, it writes the content in a file. and when i click
Solution 1:
Using new File("text1.txt")
as output does not work on Android. The current working directoy is always /
which is not writable for your app. Use
Filef=newFile(Environment.getExternalStorageDirectory(), "text1.txt");
getExternalStorageDirectory() is the internal storage for newer phones.
Your app Context has several paths that you can use if you want to store data in your app-private folder. Paths from Environment
are in public places where you can simply read the data with a filemanager
And don't forget to add
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in case you want to write to those public paths
Post a Comment for "File I/o Not Working"