BufferedCopy
- 使用BufferedReader将文件读入程序
- 使用BfrreredWriter将程序写入文件
- 只能操作字符文件,如果操作二进制文件可能导致文件损坏
代码演示
package polarbearpackage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class BufferedCopy {
public static void main(String[] args) throws Exception{
//创建源文件路径和复制文件路径
String srcFilePath = "D:\\polarBear.txt";
String destFilePath = "D:\\polarBearCopy.txt";
BufferedReader bufferedReader = new BufferedReader(new FileReader(srcFilePath));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(destFilePath));
String line;
while ((line=bufferedReader.readLine())!=null){
bufferedWriter.write(line);
bufferedWriter.newLine();
}
bufferedReader.close();
bufferedWriter.close();
}
}