- public static void main(String[] args) throws IOException {
-
- FileWriter fw = new FileWriter("c:/s1.txt");
- BufferedWriter bw = new BufferedWriter(fw);
- FileReader fr = new FileReader("c:/s1.txt");
- BufferedReader br = new BufferedReader(fr);
- FileWriter fw2 = new FileWriter("c:/s2.txt");
- BufferedWriter bw2 = new BufferedWriter(fw);
-
- bw.write("明月几时有,把酒问青天。");
-
- //尝试将这一句改为 bw.write("明月几时有,把酒问青天。\n");
- //却没有实现换行,为什么?
-
- bw.newLine();
- bw.write("不知天上宫阙,今夕是何年。");
-
- System.out.println("Copying in progress......");
-
- while(br.ready()){
- bw2.write(br.readLine());
- }
- //通过上面的循环,本意是将s1.txt中的文字复制到s2.txt中的,结果,发现s2文件为空!!
- //经过调试发现,原来br.readline()竟然为null!!为什么??
- System.out.println("Success!");
-
- bw.close();
- fw.close();
- fr.close();
- br.close();
- bw2.close();
- fw2.close();
- }
复制代码 |