Avatar of Christopher Schene
Christopher Schene
Flag for United States of America

asked on 

How do I append to a file in java?

This code I am using creates an empty file each time and thus my file contains only 1 line all the time.

What I would like to do is append to the file if it exists or create it and append if it does not exist.

private  void saveToLogFile(String s) throws FileNotFoundException {  
        PrintWriter pw=new PrintWriter(myLoggerFile);
   
        pw.append(s);  
 
        pw.flush();  
    }  
   

Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon