概述
后来改为:
public String getPath(){
URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
String path = url.toString();
int index = path.indexOf("WebRoot");
if(index == -1){
index = path.indexOf("classes");
}
if(index == -1){
index = path.indexOf("bin");
}
path = path.substring(0, index);
if(path.startsWith("zip")){//当class文件在war中时,此时返回zip:D:/...这样的路径
path = path.substring(4);
}else if(path.startsWith("file")){//当class文件在class文件中时,此时返回file:/D:/...这样的路径
path = path.substring(6);
}else if(path.startsWith("jar")){//当class文件在jar文件里面时,此时返回jar:file:/D:/...这样的路径
path = path.substring(10);
}
try {
path = URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return path;
}
读取时改为:
ReadCSV.read(path+"classes/fishtackletype.csv")
就可以了
最后
以上就是迷路煎蛋为你收集整理的web项目部署到真正服务器上后就一直找不到文件路径的全部内容,希望文章能够帮你解决web项目部署到真正服务器上后就一直找不到文件路径所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复