try {
BufferedReader reader = new BufferedReader(new FileReader(file));
BufferedWriter writer = new BufferedWriter(new FileWriter(toFile));
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
writer.flush();
}
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
- 在while当中需要用一个变量缓存读到的文本,否则会有缺失文本的情况,也就是read方法读一次就不会再读第二次