You are currently offline, waiting for your internet to reconnect

How To Redirect Output from Java Code

This article was previously published under Q252021
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
This article describes how to redirect output from Java code. This procedure differs whether you are trying to redirect output for an applet or an application.

NOTE: The ability to alter the value of System.out and other system streams may be removed or changed in the future.

How to Redirect Output for an Applet

You can enable Java logging for applets in Microsoft Internet Explorer. All output that is sent to System.out or System.err is written to a file named Javalog.txt, which is found in the C:\<windir>\Java folder (where <windir> represents your operating system).

To enable Java logging in Internet Explorer, follow these steps:
  1. On the Start menu, point to Settings, click Control Panel, and then click Internet Options.
  2. On the Advanced tab, in the Microsoft VM section, make sure that the Java logging enabled check box is selected.
NOTE: The Internet Explorer Java logging option does not affect Java applications.

How to Redirect Output for an Application

To redirect output for Java applications, perform one of the following steps:
  • Use the redirection operator (>) on the command line to redirect all standard output to a file. For example, to redirect all text output to a file named Myjavalog.txt, type the following command at a command prompt:
    jview MyJavaApp > myjavalog.txt
  • Reassign System.out to programmatically direct the output to a file or pipe. The following code, which works for jview or wjview and Internet Explorer, demonstrates how to do this:
    import*;public class JavaLogger{   public static void main (String[] args)   {      if("true".equalsIgnoreCase(System.getProperty("")))      {         try          {            // Code that writes to System.out or System.err            String logdir = System.getProperty("java.home");            PrintStream ps = new PrintStream(                             new BufferedOutputStream(new FileOutputStream(                             new File(logdir,"javalog.txt"))), true);            System.setOut(ps);                     System.setErr(ps);                  }          catch (Exception e)         {            System.out.println(e.getMessage());         }      }   }}					
For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Article ID: 252021 - Last Review: 06/14/2006 21:27:02 - Revision: 2.0

  • Microsoft Java Virtual Machine
  • kbfaq kbhowto kbjavafaq KB252021