紧急求救

jinniu123 2012-08-21 05:24:14
我在项目启动时读取配置在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();
}
...全文
87 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
scbb 2012-08-22
  • 打赏
  • 举报
回复
用下面代码打印下看看


System.out.println(new File(configPath+"config.system.properties").getAbsolutePath());
System.out.println(new File(configPath+"config.system.properties").exists());
jinniu123 2012-08-22
  • 打赏
  • 举报
回复
这里打印了是有开头的啊?
应该怎么解决
ini.load(new FileInputStream(configPath+"config.system.properties"));

scbb 2012-08-21
  • 打赏
  • 举报
回复
开头少了个/
应该是
/usr/tomcat6/we bapps/khk/WEB-INF/classes/khk/config/config. system.properties
jinniu123 2012-08-21
  • 打赏
  • 举报
回复
打印了,路径是正确的
=============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)
scbb 2012-08-21
  • 打赏
  • 举报
回复

if(osName.startsWith("Linux")){
configPath = configPath.substring(5).replace("%20", " ");
}else
configPath = configPath.substring(6).replace("%20", " ");
}

好可疑啊。。。
不能把configPath打出来看看嘛?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧