Microsoft KB Archive/252021

From BetaArchive Wiki

Article ID: 252021

Article Last Modified on 6/14/2006


  • Microsoft Java Virtual Machine

This article was previously published under Q252021


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:

    public class JavaLogger
       public static void main (String[] args)
                // 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);
             catch (Exception e)


For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Keywords: kbhowto kbfaq kbjavafaq KB252021