Question

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();
Was it helpful?

Solution 2

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top