您的位置:首页 > 编程语言 > Java开发

Java I/O学习 标准的I/O重定向

2013-11-26 14:52 204 查看
public class Test{

/*
* 标准的I/O重定向
* System.setIn(InputStream)
* System.setOut(PrintStream)
* System.setErr(PrintStream)
*/
public static void main(String[] args) throws IOException {
PrintStream console = System.out;
BufferedInputStream in = new BufferedInputStream(new FileInputStream("/home/estar/Test/a.java"));
PrintStream out = new PrintStream("and.out");

System.setIn(in);
System.setOut(out);
System.setErr(out);

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = null;
while ((s = br.readLine()) != null) {
System.out.println(s);
}
out.close();
System.setOut(console);

}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: