I mean if I’ve to create a method some kind of a: void setOutputStream(PrintStream stream).
So the stream variable is an output stream where I’ll write my data(which will preferably be a String variable).
The question is, how it will dynamically determine the output stream and correctly write my data there, i.e. for System.out it’ll print data on the screen, for file stream it’ll write my data to the file.
I mean if I’ve to create a method some kind of a: void setOutputStream(PrintStream
Share
I think you’re looking for java.lang.System#setOut(PrintStream stream) method. Which essentially lets you reassign the standard output stream programmatically.