当前位置: 代码迷 >> J2SE >> 能给解释上异常输出流吗
  详细解决方案

能给解释上异常输出流吗

热度:13   发布时间:2016-04-24 00:32:17.0
能给解释下错误输出流吗
Java code
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();    }}


我把错误输出流重定向到aaa.txt文件可是为什么出错的时候错误信息还是在控制台上显示?
aaa.txt文件根本就没有生成

------解决方案--------------------
System.setErr(ps); //重定向错误输出流
那是错误输出时的, System.out.print((char)flag);
的重定向是
System.setOut(PrintStream out) 

------解决方案--------------------
我也想明白
  相关解决方案