有下列程序代码:
import java.io.*;public class Redirecting {

public static void main(String[] args)
throws IOException {

PrintStream console = System.out;
BufferedInputStream in = new BufferedInputStream (
   new FileInputStream ("Redirecting.java"));
PrintStream out = new PrintStream (
   new BufferedOutputStream (
      new FileOutputStream("text.out")));
System.setIn(in);
System.setOut(out);
System.setErr(out);
BufferedReader br = new BufferedReader (
   new InputStreamReader (System.in));

String s;
while((s = br.readLine()) != null)
   System.out.println(s);
out.close();
System.setOut(console);
}

请问:
1)什么是标准I/O的重定向呢?有什么具体功能?为什么要重定向?
2)上面程序的功能是什么?
3)上面程序里那个:PrintStream console = System.out;是什么意思   呢?

解决方案 »

  1.   

    哦,就是把Redirecting.java文件里的内容定向输出到test.out里面去
    PrintStream console = System.out;意味着将输出内容打印在控制台上
      

  2.   

    所谓的I/O的重定向:举一个抽象的东西,比如一个箱子,2个孔,一个流入孔,一个流出孔你可以用任何流体接入流入孔,也可以用任何 流出管道\容器 接入流出孔上面的例子就是用缓冲文件流 接入System的这个流入孔,
    System的流出孔用文件out.txt作为容器接入。
    将Redirecting.java文件内容流完以后,用系统默认的流出管(console即控制台)接上System的流出孔
      

  3.   

    本来是流向 console的,现在用文件输出管道接管了 流向console的管道