Microsoft KB Archive/179021

{|
 * width="100%"|

HOWTO: Redirect Output from jview or wjview

 * }

ID: Q179021

-

The information in this article applies to:


 * Microsoft Visual J++, versions 1.0, 1.1
 * Microsoft SDK for Java, versions 1.0, 1.5, 1.51, 2.0, 2.01, 2.02, 3.0, 3.1, 3.2

-

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

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:

 Open a new Java project and call it "test." Open a new Java source file and call it "sample."  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!"); }     }   }  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.