关于重定向这个概念我不太了解,下面是一段基础代码,请大家帮我说一下,这重定向有什么用?
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("test.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); //这里为什么又改回来了?这么做有什么意义?
}
}
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("test.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); //这里为什么又改回来了?这么做有什么意义?
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货