您的位置:首页 > 运维架构 > Linux

linux与windows下读取项目文件的区别

2013-09-25 11:20 369 查看
环境:linux

容器:websphere

框架:SSH

描述:最近在做项目的时候发现,在我读取项目文件的时候出错了,而之前在windows平台是好的

解决:后来发现原因是由于在windows和linux下读取当前应用的资源文件有点小区别

windows:basePath=this.getRequest().getRealPath("/")+"XXX"+File.separator+"XXXX"+File.separator;

linux:basePath=this.getSession().getServletContext().getRealPath("/")+File.separator+"XXX"+File.separator+"XXXX"+File.separator;

故加上如下代码

String osName=System.getProperties().getProperty("os.name");

String basePath="";

if("Linux".equals(osName)||"linux".equals(osName)||"LINUX".equals(osName)){

basePath=this.getSession().getServletContext().getRealPath("/")+File.separator+"XXX"+File.separator+"XXXX"+File.separator;

}else{

basePath=this.getRequest().getRealPath("/")+"XXX"+File.separator+"XXXX"+File.separator;

}

结论:本人亲测成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐