System.in和System.out 分别是标准输入设备键盘和标准输出设备控制台,通过更改它们来达到复制文件的目的:
- package iodemo01;
- import java.io.*;
-
- public class SystemInSystemOut {
- /**
- * @param args
- */
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
-
- System.setIn(new FileInputStream("D:\\110.txt"));
- System.setOut(new PrintStream("D:\\ceshi.txt"));
- BufferedReader bfr = new BufferedReader(
- new InputStreamReader(System.in));
- BufferedWriter bfw = new BufferedWriter(
- new OutputStreamWriter(System.out));
- String line = null;
- while((line = bfr.readLine())!=null)
- {
- if("over".equals(line))
- {
- break;
- }
- bfw.write(line.toUpperCase());
- bfw.newLine();
- bfw.flush();
- }
- bfw.close();
- bfr.close();
- }
- }
复制代码
|