I want to save the output result to a text file and retrieve it whenever I want to. For writing the output to .txt, I have used the following code.
import java.io.*;
class FileOutputDemo {
public static void main(String args[])
{
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
try
{
// Create a new file output stream
// connected to "myfile.txt"
out = new FileOutputStream("myfile.txt");
// Connect print stream to the output stream
p = new PrintStream( out );
p.append ("This is written to a file");
p.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
}
}
It is working fine and the intended text file is written. But whenever I re-compile the program, the new output is written whereas the previous output is deleted. Is there a way to save the output of the previously written file and to pick up from where the previous text file left off (After re-compiling it).