Equivalent to freopen in Java

Please suggest a method to get similar behavior in Java when we do freopen ("filename", "r", stdin) OR freopen ("filename", "w", stdout) in C.

+4
source share
2 answers

Assuming this is a stdin / stdout / stderr redirect, look at System.setIn and friends. They allow you to assign different InputStream and PrintStream to System.in , System.out and System.err .

+3
source

See the web page below. There is a solution to what you want to do.

http://techtipshoge.blogspot.com/2011/01/connect-standard-io-to-files.html

+2
source

Source: https://habr.com/ru/post/1309185/


All Articles