Most read:
Popular archives:
JavaWorld's new look is here!
We've upgraded the site with a fresh look-and-feel, improved topical navigation, better search, new features, and expanded
community platform. Learn more about the changes to JavaWorld.
| Oracle Compatibility Developer's Guide |
| The Explosion in DBMS Choice |
The stream redirection demo application shows the various steps you can take to redirect all three of the standard streams to or from regular files using Java 1.1.
The java.lang.System API was changed in Java 1.1 such that the in, out, and err streams are now final. Luckily, the API was also extended to include methods to change those streams: setIn(), setOut(), and setErr(), respectively.
As before, the application presumes that a file called Redirect.in exists. It reads that file in place of the System.in standard input stream and prints it to the original System.out standard output stream. The application will redirect the System.out output stream and the System.err standard error stream to the Redirect.out and Redirect.err files, respectively.
Note that you will get warnings when compiling Redirect.java. These warnings are generated in Java 1.1 since the use of the PrintStream constructors have been deprecated. PrintStream has mostly been superseded by the PrintWriter class, but PrintStream is still used for the System.in and System.out streams. So, just ignore those deprecation warnings for this particular use
of PrintStream.
Thanks to Jeff Rhyason for prompting us for this update.