我在项目启动时读取配置在windows下读取正常,部署到centos上就找不到配置文件?求大侠指点?下边是部分代码。
String configPath = UrlDeal.decodeURIComponent(c.getResource("").toString());
if (configPath.startsWith("file:/")){
// 获得操作系统
String osName = System.getProperties().getProperty("os.name");
if(osName.startsWith("Linux")){
configPath = configPath.substring(5).replace("%20", " ");
}else
configPath = configPath.substring(6).replace("%20", " ");
}
configPath += "khk/config/";
try {
ini.load(new FileInputStream(configPath+"config.system.properties"));
System.out.println(ini.getProperty("system.log.requestmask"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

解决方案 »

  1.   


    if(osName.startsWith("Linux")){
    configPath = configPath.substring(5).replace("%20", " ");
    }else
    configPath = configPath.substring(6).replace("%20", " ");
    }好可疑啊
    不能把configPath打出来看看嘛?
      

  2.   

    打印了,路径是正确的
    =============configPath=============/usr/tomcat6/webapps/khk/WEB-INF/classes/khk/config/
    java.io.FileNotFoundException: usr/tomcat6/webapps/khk/WEB-INF/classes/khk/config/config.system.properties (No such file or directory)
      

  3.   

    开头少了个/
    应该是
    /usr/tomcat6/we bapps/khk/WEB-INF/classes/khk/config/config. system.properties
      

  4.   

    这里打印了是有开头的啊?
    应该怎么解决
    ini.load(new FileInputStream(configPath+"config.system.properties"));
      

  5.   

    用下面代码打印下看看
    System.out.println(new File(configPath+"config.system.properties").getAbsolutePath());
    System.out.println(new File(configPath+"config.system.properties").exists());