java的输出在命令行中的重定向问题
用命令行的重定向符号>>可以输出java的System.out.println信息到文件中
但是不能输出System.err.println信息到文件中
请问有没有什么办法在命令行中将System.err.println的信息也输出到文件中去?
大家可以试试
public class TestOut {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("out : hello");
System.out.println("out : world");
System.err.println("err : hello");
System.err.println("err : world");
}
}
public static void main(String[] args) throws FileNotFoundException {
OutputStream out = new FileOutputStream("hello.txt");
PrintStream ps = new PrintStream(out);
System.setOut(ps);
System.setErr(ps);
System.out.println("out : hello");
System.out.println("out : world");
System.err.println("err : hello");
System.err.println("err : world");
}