/**
* 重定向输出
* @throws IOException
*/
public void printWriter() throws IOException {
// 标准输入流
// BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
PrintStream console = System.out;
BufferedInputStream in = null;
PrintStream out = null;
try {
in = new BufferedInputStream(new FileInputStream("E:/test.java"));
out = new PrintStream(new BufferedOutputStream(new FileOutputStream("E:/copy.txt")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (null != in) {
System.setIn(in);
}
if (null != out) {
System.setOut(out);
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s;
// 重定向标准输出到文件
while ((s = br.readLine()) != null) {
System.out.println(s);
}
// 输出到标准输出设备
System.setOut(console);
while ((s = br.readLine()) != null) {
System.out.println(s);
}
if (null != out) {
out.close();
}
}