Android append text file

后端 未结 3 1788
眼角桃花
眼角桃花 2020-11-30 07:03

I am tring to record the wake time and sleep time from a dialog picker to a text file like this, but the call to the method commitToFile2 doesn\'t append the text file \"sa

相关标签:
3条回答
  • 2020-11-30 07:09

    In your commitToFile2() method, after fw.append(entryString); try adding fw.flush();

    FileWriter is a subclass of OutputStreamWriter and the write() methods of that class will not necessarily 'flush' data automatically.

    0 讨论(0)
  • 2020-11-30 07:14

    that's so you retain your MODE_WORLD_READABLE

    openFileOutput("savedData.txt", MODE_APPEND | MODE_WORLD_READABLE ); 
    
    0 讨论(0)
  • 2020-11-30 07:16

    I figured it out....I had to change the line

    FileOutputStream fOut = openFileOutput("savedData.txt", MODE_WORLD_READABLE);
    

    to

    FileOutputStream fOut = openFileOutput("savedData.txt",  MODE_APPEND);
    

    After that I was able to append the text file without overwriting the data that was already inside the text file. Thanks for your assistance guys. I guess going to the 4th page on google IS useful sometimes.

    0 讨论(0)
提交回复
热议问题