01-錯誤信息:
Exception in thread "main" java.io.FileNotFoundException: e:\bb (拒絕訪問。)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.eleven.SevenDemo04.copyFile(SevenDemo04.java:44)
at com.eleven.SevenDemo04.main(SevenDemo04.java:21)
02-代碼:
1)修改前:
public static void main(String[] args) throws Exception {
File source = new File("d:\\aa\\aa.txt"); // 源目標路徑
File dest = new File("e:\\bb\\"); // 目標路徑
copyFile(source, dest);
}
2)修改後:
錯誤的原因是讀取的目錄後面忘加了文件名!
public static void main(String[] args) throws Exception {
File source = new File("d:\\aa\\aa.txt"); // 源目標路徑
File dest = new File("e:\\bb\\" + source.getName()); // 目標路徑
copyFile(source, dest);
}