Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of freopen in Java

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

like image 460
avd Avatar asked May 08 '10 11:05

avd


2 Answers

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

like image 110
Thomas Avatar answered Sep 22 '22 15:09

Thomas


See the webpage below. There's a solution to what you wanna do.

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

like image 30
ken Avatar answered Sep 23 '22 15:09

ken