views:

193

answers:

2

I am working on the Android SDK on Eclipse.

Whenever I look at the SDcard after running this code (either before or after closing the emulator) the file exists but its contents are empty. I have tried reading the contents after writing them, with a BufferedReader, and they are indeed there, but vanish when I open the file.

File file = new File(Constants.UPDATE_FILE);
final java.util.Calendar c = java.util.Calendar.getInstance();
if(!file.exists())
{
    Log.i(TAG, "create new file");
    file.createNewFile();
    lastUpdate = c.getTime();
}

BufferedWriter bufferedFileWriter = new BufferedWriter(new FileWriter(file));
String dateToWrite = c.getTime().toGMTString();
bufferedFileWriter.write(dateToWrite);
bufferedFileWriter.flush();
bufferedFileWriter.close();
+2  A: 

Hm. You should make sure that your application has the WRITE_EXTERNAL_STORAGE permission, aaannd maybe open the file with an access mode.

moritz
A: 

Well, it's an emulator problem. Testing on the actual device reveals no flaws.

Júlio Santos
Back to moritzs comment, if the device is running say 1.5 and emulator 2.0 the permission (i think) will be needed!
Laurence Dawson