✅ 操作成功!

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

发布时间:2023-06-16 作者:admin 来源:文学

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

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

环境: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; }

结论:本人亲测成功

👁️ 阅读量:0