您可以在程序的开头包含以下几行:
final PrintStream origout = System.out;final PrintStream fileout = new PrintStream(file);System.setOut(new PrintStream(new OutputStream() { @Override public void write(int b) throws IOException { origout.write(b); fileout.write(b); }}));


