Appending to a file to write to
Hi everyone, I am new to input/output streaming, and I just want to know how to append to a file.
Here is my code:
Code:
s = "this is my text"
public static void main(String[] args) throws IOException {
PrintWriter outputStream = null;
try {
outputStream = new PrintWriter(new FileWriter("output.txt"));
outputStream.println(s);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
It does write to the output, but when I change the value of s and rerun the program, it just erases what was there before and writes on top of it. Is there a separate command for appending to a file and will it start on a new line?
also, how would I indicate the path, right now it just puts it in my project folder.
Thanks