读代码没什么问题,但想输出到to.txt,一直不成功
- Java code
import java.io.*;class Test{ public static void main(String agrs[]){ FileReader fr = null; FileWriter fw = null; BufferedReader br = null; BufferedWriter bw = null; try{ fr = new FileReader("C:/Users/Administrator/Desktop/运行代码/from.txt"); fw = new FileWriter("C:/Users/Administrator/Desktop/运行代码/to.txt"); br = new BufferedReader(fr); bw = new BufferedWriter(fw); String line = null; while(true){ line = br.readLine(); if(line == null){ break; } System.out.println(line); //这个有显示 bw.write(line); //就是这里了,不知道是什么问题 } } catch(Exception e){ System.out.println(e); } finally{ try{ fw.close(); br.close(); fr.close(); br.close(); } catch(Exception e){ System.out.println(e); } } }}
------解决方案--------------------------------------------------------
bw.flush()