Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.


+15 votes
asked in CSC211_Winter2018 by (8 points)

1 Answer

+5 votes

The definition of PrintStream prof. Mueller used in her presentation today was the following.
PrintStream: An object in the java.io package that lets you print output to a destination such as a file.

So I would assume that PrintStream could be used when the output isn't specified or we want multiple outputs from a method call.

PrintStream out1 = System.out;
PrintStream out2 = new PrintStream(new File("data.txt"));
out1.println("Hello, console!"); // goes to console
out2.println("Hello, file!"); // goes to file

This is the example she used in the presentation.
She also displayed calling the same method but just changing the destination in the call by having the method use PrintStream instead of a specific output.
Meaning she was able to call the same method twice but one with System.out and the other to a file path.

answered by (8 points)