java文件操作報錯:java.io.FileNotFoundException(拒絕訪問)問題
java文件操作報錯:java.io.FileNotFoundException(拒絕訪問)
錯誤信息
Exception in thread "main" java.io.FileNotFoundException: e:b (拒絕訪問。)
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)
代碼
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); }
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
spring無法引入注解及import org.springframework.web.bind.annota
本文主要介紹了spring無法引入注解及import org.springframework.web.bind.annotation.*報錯的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-06-06