public class BufferedCopy_ {
public static void main(String[] args) {
/**
* 特别说明
* 1.BufferedReader 和 BufferedWriter 是按照字符操作的
* 2.不要去操作二进制文件(声音,视频,doc,pdf...),可能会造成文件损坏
*/
String srcFilePath = "d:\\a.txt";
String destFilePath = "d:\\apro.txt";
BufferedReader br = null;
BufferedWriter bw = null;
String line;
try {
br = new BufferedReader(new FileReader(srcFilePath));
bw = new BufferedWriter(new FileWriter(destFilePath));
//说明:readLine 读取一行内容,但是没有换行
while ((line = br.readLine()) != null) {
//每读取一行,就写入
bw.write(line);
//插入一个换行符
bw.newLine();
}
System.out.println("拷贝完毕···");
} catch (IOException e) {
e.printStackTrace();
} finally {
//关闭流
try {
if (br != null) {
br.close();
}
if (bw != null) {
bw.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
标签:String,BufferedWriter,BufferedReader,bw,br,拷贝,null
From: https://www.cnblogs.com/cyyyds/p/17065433.html