问题描述
首先,本地是用tomcat服务器windows开发环境的,没有问题Stringpath=this.getClass().getClassLoader().getClassLoader().getResource("/").getPath();if("\".equals(File.separator)){path=path.substring(1,path.indexOf("/WEB-INF/classes"));path=path.replace("/","\");}if("/".equals(File.separator)){path=path.substring(0,path.indexOf("/WEB-INF/classes"));path=path.replace("\","/");}上面的path就是下面的newPath部署上去是weblogic服务器linux运行,部署要为war包下就总是错误,是在输出文件的时候出错FileInputStreamfi=newFileInputStream(oldPath);BufferedInputStreamin=newBufferedInputStream(fi);FileOutputStreamfo=newFileOutputStream(newPath);BufferedOutputStreamout=newBufferedOutputStream(fo);这里就出错了。也试过很多取path的方法,比如request.XXX的。。都不行测试都没问题,部署上去出错
解决方案
解决方案二:
先不考虑是否会在重新部署后丢失文件。如果提供的思路能解决丢文件,那么是最好的。
解决方案三:
weblogic里面不要使用war包部署,war包的话,weblogic不会自动解压,这样里面的路径是拿不到的将war包解压出来,部署文件包,然后获取路径,再定文件存放地址参考下weblogic下面classpath路径获取
解决方案四:
另外,不要求使用写死路径的方法。寻求其他方法