import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class SystemOutRedirect {
public static void main(String[] args) throws FileNotFoundException {
System.setOut(new PrintStream(new FileOutputStream("stdout.txt")));
System.setErr(new PrintStream(new FileOutputStream("error.txt")));
System.out.println("hello"); //goes to stdout.txt
System.err.println("error"); //goes to error.txt
}
}
Pages
Tuesday, August 2, 2011
Code Snippet: Redirecting Standard Output to File
Labels:
code snippet,
Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment