Microsoft SDK for Java

Q179021 HOWTO: Redirect Output from jview or wjview.

The information in this article applies to:

SUMMARY

This article describes two methods that can redirect output from jview or wjview.

MORE INFORMATION

Method 1

Unfortunately, there is not an option or registry setting for jview or wjview that enables Java logging. However, you can redirect the output when invoking an application like the following example:

jview main > javalog.txt

This works for both jview and wjview.

Method 2

Or you can programmatically direct the output to a file or pipe by reassigning System.out. The following steps, which work for jview or wjview and Internet Explorer, show how this can be done:

  1. Open a new Java project and call it "test."

  2. Open a new Java source file and call it "sample."

  3. Copy and paste the following code in the file you created in step 2.
         // 
          // sample.java
          // 
          import java.io.*;
          public class sample {
             public static void main(String[] args)
             {
                if ("true".equalsIgnoreCase(System.getProperty
                      ("com.ms.applet.enable.logging")))
                {
                   try
                   {
                      String logdir = System.getProperty("java.home");
                      PrintStream ps = new PrintStream(new 
    BufferedOutputStream
                            (new FileOutputStream(new File
                            (logdir,"javalog.txt"))), true);
               // Use the following two lines for SDK 1.5 and 1.5.1:
                      // System.out = ps;   // comment line if using SDK 2.0
                      // System.err = ps;   // comment line if using SDK 2.0
               // Otherwise, use the following two lines for SDK 2.0 and 
    greater:
                     System.setOut(ps);     // uncomment line if using SDK 2.0
                      System.setErr(ps);    // uncomment line if using SDK 2.0
                   }
                   catch (Exception e)
                   {
                   }
                   System.out.println("sample.java executed successfully!");
                }
             }
          }
  4. Build and execute the above project.

    Javalog.txt should contain the line: "sample.java executed successfully!".

Note   Javalog.txt is normally found in your Windows directory at %Windir%\Java\Javalog.txt.

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

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

Q177177 HOWTO: Enabling Messages Printed Using System.out.println

Q173469 How to Enable the Javalog.txt File

For the latest Knowledge Base articles and other support information on Microsoft® Visual J++® and the SDK for Java, please see the following pages on the Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/ This link takes you to a site on microsoft.com

http://support.microsoft.com/support/java/ This link takes you to a site on microsoft.com

© 1999 Microsoft Corporation. All rights reserved. Terms of use.