有下列程序代码:
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;是什么意思 呢?
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;是什么意思 呢?
PrintStream console = System.out;意味着将输出内容打印在控制台上
System的流出孔用文件out.txt作为容器接入。
将Redirecting.java文件内容流完以后,用系统默认的流出管(console即控制台)接上System的流出孔