0

Is it somehow possible to print both to file and console?

If I make

PrintStream fileStream = new PrintStream(logPath);
System.setOut(fileStream);

it will only print all System.out.println() to file, but I also need to see it in console.

Dimitry
  • 99
  • 6
  • 2
    why not make your own logger class, that performs both, – Stultuske Apr 19 '21 at 11:32
  • 1
    I am with @Stultuske here - the use of `System.out` / `System.err` in production code is discouraged anyway. Just take a look at SLF4J - and don't use log4j. The latter will give you severe headache. – maio290 Apr 19 '21 at 11:35

1 Answers1

-2

Yes it is.You just need to write your file using Buffer writers and use S.O.P at the end of the function or according to the things you want to print to your console.

  • I think you are getting negative comments for the dismissive answer. Giving some details (e.g. a possible implementation, with the full class name) would help you to get more upvotes. – pierpytom Apr 29 '21 at 08:27