我是靠谱客的博主 迷路煎蛋,这篇文章主要介绍web项目部署到真正服务器上后就一直找不到文件路径,现在分享给大家,希望可以做个参考。

后来改为:

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项目部署到真正服务器上后就一直找不到文件路径内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部