关于“ java.io.FileNotFoundException: C:\Program%20Files\Apache%20Software%20Foundation\”的类似问题
2014-12-11 12:07
656 查看
昨天在项目中遇到了一个问题,
问题如下:如图
在项目中想要读取这两个文件。
相应的代码为: BufferedReader reader2=new BufferedReader(new FileReader(PrivaligeFilter.class.getResource("/user.txt").getFile()));
结果出现如下错误:
java.io.FileNotFoundException:C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%207.0\webapps\MyStore\WEB-INF\classes\user.txt (系统找不到指定的路径。).
看错误的原因“%20”的位置应该是空格,出错的原因应该就是路径中存在空格后的编码问题;
对代码做如下修改:
String path = this.getClass().getResource("/admin.txt").getFile();
try {
path = java.net.URLDecoder.decode(path, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
然后再运行,搞定!
问题如下:如图
在项目中想要读取这两个文件。
相应的代码为: BufferedReader reader2=new BufferedReader(new FileReader(PrivaligeFilter.class.getResource("/user.txt").getFile()));
结果出现如下错误:
java.io.FileNotFoundException:C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%207.0\webapps\MyStore\WEB-INF\classes\user.txt (系统找不到指定的路径。).
看错误的原因“%20”的位置应该是空格,出错的原因应该就是路径中存在空格后的编码问题;
对代码做如下修改:
String path = this.getClass().getResource("/admin.txt").getFile();
try {
path = java.net.URLDecoder.decode(path, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
然后再运行,搞定!
相关文章推荐
- 关于IO流在复制文件时出现java.io.FileNotFoundException: D:\xxx (拒绝访问。) 拒绝访问的问题
- java.io.FileNotFoundException问题,说是db.properties文件找
- 关于写入文件缓存时报"java.io.FileNotFoundException open failed (is a director)"错误的解决方法
- ssm框架问题Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/mybatiscon
- 解决java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题
- 解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)问题
- 打开Openfire 关于出现 java.io.FileNotFoundException: 等错误信息
- java.io.FileNotFoundException问题,说是db.properties文件找不到,但是在webapps里存在的
- java.io.FileNotFoundException: E:\test (拒绝访问。)问题
- java.io.FileNotFoundException: /data/user/0/**/cache/img1.jpg: open failed: ENOENT 问题解决
- 写文件流报:java.io.FileNotFoundException.....\img (拒绝访问。)的问题真正病根
- android编程中遇到的关于java.io.FileNotFoundException: /mnt/sdcard/update.zip (Permission denied)错误的原因及解决办法
- [原]在Oracle SOASUITE 10g 调用ESB 报“java.io.FileNotFoundException: /u01/esb/product/10.1.3.1/j2ee/home/../Context.properties”问题的解决办法
- 解决java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题
- java 关于FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题解析
- 解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)问题
- Android java.io.FileNotFoundException: open failed: EACCES (Permission denied) 问题未解决!!
- 解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)问题
- 使用Ant编译出现如下问题 java.io.FileNotFoundException: bin\classes.dex
- 解决java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题