Microsoft KB Archive/252021: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 78: | Line 78: | ||
public static void main (String[] args) | public static void main (String[] args) | ||
{ | { | ||
if( | if("true".equalsIgnoreCase(System.getProperty("com.ms.applet.enable.logging"))) | ||
{ | { | ||
try | try | ||
{ | { | ||
// Code that writes to System.out or System.err | // Code that writes to System.out or System.err | ||
String logdir = System.getProperty( | String logdir = System.getProperty("java.home"); | ||
PrintStream ps = new PrintStream( | PrintStream ps = new PrintStream( | ||
new BufferedOutputStream(new FileOutputStream( | new BufferedOutputStream(new FileOutputStream( | ||
new File(logdir, | new File(logdir,"javalog.txt"))), true); | ||
System.setOut(ps); | System.setOut(ps); | ||
System.setErr(ps); | System.setErr(ps); |
Latest revision as of 13:52, 21 July 2020
Article ID: 252021
Article Last Modified on 6/14/2006
APPLIES TO
- Microsoft Java Virtual Machine
This article was previously published under Q252021
SUMMARY
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.
MORE INFORMATION
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:
- On the Start menu, point to Settings, click Control Panel, and then click Internet Options.
- 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 java.io.*; public class JavaLogger { public static void main (String[] args) { if("true".equalsIgnoreCase(System.getProperty("com.ms.applet.enable.logging"))) { 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()); } } } }
REFERENCES
For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
Keywords: kbhowto kbfaq kbjavafaq KB252021