1

I want to write the results of my tests to an already created text file using PrintStream. Unfortunately i only know about this statement

PrintStream out = new PrintStream(new FileOutputStream("Results.txt"))

but this is creating a new file. Removing new from the statement won't work.

So, what is the command to write in Results.txt without deleting the previous results/creating a new one?

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
Tudor
  • 199
  • 3
  • 14

1 Answers1

7

Use this constructor to open the file in append mode :

public FileOutputStream(String name, boolean append)

i.e.

PrintStream out = new PrintStream(new FileOutputStream("Results.txt",true));
Eran
  • 387,369
  • 54
  • 702
  • 768