Link to home
Start Free TrialLog in
Avatar of Christopher Schene
Christopher ScheneFlag 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();  
    }  
   

SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Christopher Schene

ASKER

Oh --- never thought of using a logging class. I can ask another question about use of the logging class(es).
CEJH --- I am going to ask another question about Java logging --- I should have figured there would be a class for that.
Righto