今天在手寫動態代理的時候使用File類創建文件報錯:java.io.FileNotFoundException: C:\... (拒絕訪問。)
public class Test {
public static void main(String[] args) {
Class<?>[] interfaces = new Class[]{Dao.class};
byte bytes[] = ProxyGenerator.generateProxyClass("AA", interfaces);
File file = new File("C:\\Users\\97307\\Downloads");
try {
FileOutputStream fw = new FileOutputStream(file);
fw.write(bytes);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
報錯類型:
一開始以爲是文件夾權限的問題,設置完發現還是不行,最後才發現自己又犯了很久之前已經犯過的錯誤,在指定文件生成路徑的時候忘了加要生成文件的文件名= =。
public class Test {
public static void main(String[] args) {
...
File file = new File("C:\\Users\\97307\\Downloads\\Test.class");
...
}
}
這次特地記錄一下希望下次不要再犯。