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

1 篇文章 0 订阅

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

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

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值