public class TransStreamDemo2 {
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw = null;
try {
/*
效果等同于复制:
重新设置标准输入输出流
System.setIn(new FileInputStream("D:"+File.separator+"a.txt"));
System.setOut(new PrintStream("D:"+File.separator+"b.txt"));
*/
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
String buf = null;
while((buf = br.readLine()) != null){
bw.write(buf);
bw.newLine();
}
} catch (IOException e) {
throw new RuntimeException("文件操作失败");
} finally {
try {
if (br != null)
br.close();
} catch (IOException e) {
throw new RuntimeException("流关闭失败");
}
try {
if (bw != null)
bw.close();
} catch (IOException e) {
throw new RuntimeException("流关闭失败");
}
}
}
}