import java.io.*;
public class Test {
public static void main(String[] args) {
copy();
}
public static void copy() // 创建一个方法用于复制文件
{
FileWriter fw = null;
FileReader fr = null;
try {
fr = new FileReader("day21-笔记.txt");
fw = new FileWriter("word.txt");
char[] buf = new char[1024];
int len = 0;
while ((len = fr.read(buf)) != -1) {
fw.write(buf, 0, len);
}
} catch (IOException e) {
throw new RuntimeException("读写失败");
} finally {
if (fr != null)
try {
fr.close();
} catch (IOException e) {
}
if (fw != null)
try {
fw.close();
} catch (IOException e) {
}
}
}
}
代买没啥问题,看下你读的文件存在吗?这是我的文件路径,运行正常 |