append to file android

前端 未结 1 1077
余生分开走
余生分开走 2021-01-02 05:59

hey there, i need to append to my file but it is not working, it keeps overwriting the file, can anyone please tell me what is wrong:

  public void generate         


        
相关标签:
1条回答
  • 2021-01-02 06:22

    You can fix it by changing the line where you assign the BufferedWriter:

    bW = new BufferedWriter(new FileWriter(gpxfile, true));
    

    When you open a file using the FileWriter constructor that only takes in a File, it will overwrite what was previously in the file. Supplying the second parameter as true tells the FileWriter that you want to append to the end of it.

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