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
  • 22,426
  • 8
  • 47
  • 70
Tudor
  • 149
  • 3
  • 12

1 Answers1

6

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
  • 374,785
  • 51
  • 663
  • 734