我在项目启动时读取配置在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();
}
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();
}
解决方案 »
- java.lang.OutOfMemoryError: unable to create new native thread
- js动态生成txt文本框,统计文本框的和
- JAVA程序员找工作
- tomcat和hibernate调优
- 用hibernate插入oracle数据库Date字段的问题
- 为什么我连接java.com检查我是否安装了java时会弹出让我登陆
- MyEclipse 中写struts程序路径的问题, 急急急!!!
- 利用Axis库调用C#的Web Service
- 连接池泄漏问题,高分求,在线等
- 为什么要使用EJB?使用EJB能带来什么好处?又有什么劣势?
- 日历管理功能
- Java泛型的理解
if(osName.startsWith("Linux")){
configPath = configPath.substring(5).replace("%20", " ");
}else
configPath = configPath.substring(6).replace("%20", " ");
}好可疑啊
不能把configPath打出来看看嘛?
=============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)
应该是
/usr/tomcat6/we bapps/khk/WEB-INF/classes/khk/config/config. system.properties
应该怎么解决
ini.load(new FileInputStream(configPath+"config.system.properties"));
System.out.println(new File(configPath+"config.system.properties").getAbsolutePath());
System.out.println(new File(configPath+"config.system.properties").exists());