1. 程式人生 > >Exception in thread "main" java.io.FileNotFoundException: E:\\a (拒絕訪問。)

Exception in thread "main" java.io.FileNotFoundException: E:\\a (拒絕訪問。)

File src = new File(“E:\\a”);
BufferedReader br = new BufferedReader(new FileReader(src));//報錯的是這行
報錯如下:
Exception in thread “main” java.io.FileNotFoundException: E:\a (拒絕訪問。)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at java.io.FileReader.(FileReader.java:72)
at com.liyu.fileAndIO.IOTest2.main(IOTest2.java:14)

解決思路:當src是資料夾就會報這個錯,因為輸入流不能讀取資料夾,把他換成檔案file就OK。
PS 當你在進行資料夾的複製的時候要檢查程式碼是不是讀取的是資料夾。