Posted on 2012-04-15 16:37
zljpp 阅读(1281)
评论(0) 编辑 收藏
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
public class Redirecting {
public static void main(String[] args) throws IOException {
PrintStream console = System.out;
BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("src/com/io/Redirecting.java").getAbsolutePath()));
PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File("src/com/io/").getAbsolutePath() +"/test.out")),true);//第二个参数很重要
System.setIn(in);
System.setOut(out);
System.setErr(out);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String s;
while((s = reader.readLine())!= null){
System.out.println(s);
out.close();
System.setOut(console);
}
}
}