Hi Everyone,
I'm new to android development, the following is the code that am
using to create a small text file on the external storage. but the
problem is its saying can't read nd can't write.. Can any one help me
out.. please
Note : bollo() is a method with has a toast to display on the screen
dont confuse with that method.
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable =
true;
bollo("Storage is mounted and ready to use");
try {
File root = Environment.getExternalStorageDirectory);
if (root.canWrite()) {
File myFile = new File(root, "test.txt");
FileWriter myFileWriter = new FileWriter(myFile);
BufferedWriter out = new BufferedWriter(myFileWriter);
out.write("Hello Android Community");
out.close();
}
else
{
bollo("media not writable");
if(root.canRead())
{
bollo(root.getPath());
}
else
{
bollo("media not readable");
}
}
} catch (IOException e) {
Log.e("EXT", "Error writing file: " + e.getMessage());
bollo("Error");
}
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Toast.makeText(this, "Storage is mounted and ready to use
but
not writable", Toast.LENGTH_LONG).show();
} else {
// Something else is wrong. It may be one of many other
states,
but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable =
false;
Toast.makeText(this, "Storage is not mounted and not ready
to
use", Toast.LENGTH_LONG).show();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en