gpt4 book ai didi

java - 使用目录时 URLClassLoader 有什么问题?

转载 作者:行者123 更新时间:2023-12-01 15:45:03 27 4
gpt4 key购买 nike

这是我的代码:

File folder = /* the folder with a.txt file */
final URL[] urls = new URL[] {
folder.toURI().toURL()
};
ClassLoader loader = new URLClassLoader(urls);
assertThat(loader.getResource("/a.txt"), is(notNullValue()));

不起作用。 getResource() 返回NULL。为什么?

最佳答案

因为资源名称始终与您构建类加载器所用的类路径相关。您不能使用绝对名称(即以 / 开头的名称)。

关于java - 使用目录时 URLClassLoader 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7219367/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com