看代码就懂:
package com.xs.test;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class Test {
public static void main(String[] args) throws Exception {
String outPath = "C:\\out.log";
System.setOut(new PrintStream(new FileOutputStream(outPath, true)));
System.out.println("Hello world!");
}
}
程序中所有的标准输出就保存到文件了。