有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

为什么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 = Nullpath=./../config/equipmenttemplates/已经存在了


共 (0) 个答案