public class Text08 {
public static void main(String[] args) {
FileReader fileReader = null;
BufferedReader reader = null;
FileWriter fileWtite = null;
BufferedWriter write = null;
try {
fileReader = new FileReader("index.txt");
reader = new BufferedReader(fileReader);
fileWtite = new FileWriter("copy1.txt");
write = new BufferedWriter(fileWtite);
String str = "";
while ((str = reader.readLine()) != null) {
write.flush();//刷新缓冲区 ()
write.write(str);
write.write("\n");
write.newLine();
}
} catch (FileNotFoundException e) {
System.out.println("文件找不到"+e.getMessage());
}catch (IOException e) {
System.out.println("io读写异常"+e.getMessage());
}finally{
try {
reader.close();
write.close();
fileReader.close();
fileWtite.close();
} catch (Exception e2) {
System.out.println("文件关闭异常"+e2.getMessage());
}
}
}
}
网友评论