Write to text file without overwriting in Java

前端 未结 9 1372
失恋的感觉
失恋的感觉 2020-11-30 05:02

I am trying to write a method that makes a \"log.txt file\" if one does not already exist and then writes to the file. The problem that I am encountering is every time I cal

9条回答
  •  情话喂你
    2020-11-30 05:25

    You can change your PrintWriter and use method getAbsoluteFile(), this function returns the absolute File object of the given abstract pathname.

    PrintWriter out = new PrintWriter(new FileWriter(log.getAbsoluteFile(), true));

提交回复
热议问题