public class CopyFile {
public static void main(String[] args) throws IOException {
// 封装数据源和目的地
BufferedReader br = new BufferedReader(new FileReader(
"Test.java"));
BufferedWriter bw = new BufferedWriter(new FileWriter("b.java"));
// 一次一个字符
// int ch = 0;
// while ((ch = br.read()) != -1) {
// bw.write(ch);
// // bw.flush();
// }
// 一次一个字符数组
char[] chs = new char[1024];
int len = 0;
while ((len = br.read(chs)) != -1) {
bw.write(chs, 0, len);
}
// 释放资源
bw.close();
br.close();
}
} |