Writing String to Text File

后端 未结 6 1681
太阳男子
太阳男子 2021-01-29 01:21

I am saving a log to a .txt file on the sdcard but once there is two lines saved, it overwrites it and starts over?

Here is my code:

public static Strin         


        
6条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 01:50

    Try changing

    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFile, true)));
    

    to

    FileWriter fileWritter = new FileWriter(logFile,true); //true = append file
    BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
    bufferWritter.write(YourData);
    bufferWritter.close();
    

提交回复
热议问题