5

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.

razlebe
  • 6,916
  • 6
  • 38
  • 53
avd
  • 12,513
  • 29
  • 74
  • 96
  • Do you have any code you've already tried? – razlebe May 08 '10 at 11:36
  • I am new to Java. I know C++ properly. So if you could please provide a code snippet. I just know how to read from stdout through bufferedReader. – avd May 08 '10 at 11:39

2 Answers2

3

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.

Thomas
  • 150,847
  • 41
  • 308
  • 421
2

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

ken
  • 21
  • 1