Problem saving on sdcard of Nexus S
I cannot save a text file o开发者_JAVA技巧n a Nexus S. State is mounted, path is ok (/sdcard/filename
), there is a permission in my manifest file for extenal storage.
The program gives an IOException
on this line:
File file = new File(path, fileName + ".txt");
I have no idea how to detect the problem, especially if it works fine on a Galaxy Mini. I have been struggling saving a txt file on Samsung Galaxy for some time, but made it work by removing a line from the manifest file defining the min sdk version. It did not accept any min sdk version in fact, so I removed it altogether for now...
Can anyone help?
String path= Environment.getExternalStorageDirectory().toString()+"/";
File file = new File(path+fileName + ".txt");
try it out
As described in the docs, you should first check that external media is mounted:
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
and then use it via Environment.getExternalStorageDirectory()
.
If you plan to save publicly accessed files (pictures, videos, music, etc..) then use Environment. getExternalStoragePublicDirectory(..)
with appropriate argument.
精彩评论