日期:2014-05-20 浏览次数:20692 次
import java.io.*; public class TestRedirect { public static void main(String[] args)throws IOException,FileNotFoundException { FileInputStream fis=new FileInputStream("e:\\TestGridBag1.java"); PrintStream ps=new PrintStream(new FileOutputStream("e:\\aaa.txt")); System.setErr(ps); //重定向错误输出流 int flag=0; while((flag=fis.read())>0) { System.out.print((char)flag); } fis.close(); ps.close(); } }