赞
踩
今天在手写动态代理的时候使用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");
- ...
- }
- }
这次特地记录一下希望下次不要再犯。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。