利用标准I/0重定向进行文件的复制

PrintStream ps = System.out;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:/data.txt"));
PrintStream out = new PrintStream(new FileOutputStream("d:/datacopy.txt"));
System.setIn(bis);
System.setOut(out);

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String s;
while((s = br.readLine()) != null){
System.out.println(s);
}
out.close();
System.setOut(ps);

你可能感兴趣的:(System,printstream)