日期:2014-05-19  浏览次数:20640 次

求助 文件路径问题
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
你应该换一种方式去试试
------解决方案--------------------
你把"\"的全都替换成"/"试试