为什么Java代码在Windows中的资源路径为空?
我正在写一个文件的路径
if (!new File(path).exists()) {
URL location = this.getClass().getClassLoader().getResource(path);
if (location == null) {
location = Thread.currentThread().getContextClassLoader().getResource(path);
}
path = location.getPath();
path = URLDecoder.decode(path, "utf-8");
path = new File(path).getPath();
if (!new File(path).exists()) {
throw new Exception("Unable to resolve path: " + path);
}
}
同样的代码在Linux机器上运行,但在Windows上我得到了location = Null
和path=./../config/equipmenttemplates/
已经存在了
共 (0) 个答案