You need to use FileWriter (pure Java (6 or 7)), not PrintWriter from the processing API. FileWriter has a second argument in the constructor that allows you to set a boolean value to decide whether you will add an output or overwrite it (true to add, false to overwrite).
The documentation is here: http://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html Note that you can also use BufferedWriter and pass it to the FileWriter constructor in the constructor, if at all helps (but I do not consider it necessary in your case).
Example:
try { FileWriter output = new FileWriter("example.csv",true); //the true will append the new data output.println("a;b;c;this;that "); output.flush(); output.close(); } catch(IOException e) { println("It Broke :/"); e.printStackTrace(); }
As above, this will work in PDE - and in Android - but if you need to use it in PJS, PyProcessing, etc. then you have to hack it
- dynamically read the length of an existing file and store it in an ArrayList
- add new line to ArrayList
- use the ArrayList index to control where in the file you are currently writing.
If you want to suggest an improvement to the PrintWriter API (which is probably based on FileWriter), you can do this on the "Handling Issues" page on GitHub:
https://github.com/processing/processing/issues?state=open
source share