Java使用File类生成文件报错:java.io.FileNotFoundException: C:\... (拒绝访问。)

今天在手写动态代理的时候使用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");
        ...
    }
}

这次特地记录一下希望下次不要再犯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章