首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

文件路径有关问题

2013-01-02 
求助 文件路径问题Propertiespropnew Properties()String path getClass().getProtectionDomain().get

求助 文件路径问题

Properties  prop=new Properties();
   String path = getClass().getProtectionDomain().getCodeSource()
     .getLocation().getPath();
   path = path.substring(0, path.indexOf("classes")+8);
FileInputStream in=new FileInputStream(path+"library.properties");
 
运行结果:java.io.FileNotFoundException: D:\Program%20Files\apache-tomcat-7.0.30\webapps\LibrarySystem\WEB-INF\classes\library.properties (系统找不到指定的路径。)。
但是把D:\Program Files\apache-tomcat-7.0.30\webapps\LibrarySystem\WEB-INF\classes\library.properties复制到文件地址栏可以找到文件。大神求解释
[解决办法]
把部署到TOMCAT中的工程删掉重新部署后再试试
[解决办法]
你的路径存在空格:Program Files
String path = getClass().getProtectionDomain().getCodeSource()
             .getLocation().getPath();
这种方式获取路径的一个bug
你应该换一种方式去试试
[解决办法]
你把""的全都替换成"/"试试

热点排行
Bad Request.