import java.io.*;
public class Main {
public static void main(
String[]
args)
throws IOException{
BufferedReader bd =
null;
BufferedWriter bw =
null;
try {
bd =
new BufferedReader(
new FileReader(
"Demo.txt"));
//从Demo.txt文件中读取数据
bw =
new BufferedWriter(
new FileWriter(
"Demo_copy.txt"));
//写入到Demo_copy.txt中
String line =
null;
while ((
line =
bd.
readLine())!=
null){
bw.
write(
line);
bw.
newLine();
bw.
flush();
}
}
catch (
IOException e){
System.
out.
println(
"读写失败");
}
finally {
if(
bd!=
null){
try {
bd.
close();
}
catch (
IOException e){
System.
out.
println(
"读取关闭失败");
}
}
if(
bw!=
null){
try {
bw.
close();
}
catch (
IOException e){
System.
out.
println(
"写入关闭失败");
}
}
}
}
}
转载请注明原文地址: https://www.6miu.com/read-2613533.html