System.setOut(new PrintStream("c:\test.txt"));
System.out.println("line1");
System.setOut(System.out);
System.out.println("line2");
上面这段代码在重定向输出到test.txt后,又回到标准输出,为什么没有生效?line1和line2都打印到test.test里面去了。
System.setOut(new PrintStream("c:\test.txt"));
System.out.println("line1");
System.setOut(System.out);
System.out.println("line2");
上面这段代码在重定向输出到test.txt后,又回到标准输出,为什么没有生效?line1和line2都打印到test.test里面去了。
[code="java"] PrintStream o = System.out;
System.setOut(new PrintStream("1.txt"));
System.out.println("line1");
System.setOut(o);
System.out.println("line2");[/code]
如果你有好方法请联系我一下,这东西没用过