无法在最新的JVM版本上加载JAR的资源

发布于 2025-02-10 19:42:08 字数 480 浏览 2 评论 0原文

从JAR文件(png构建Imageicon)加载资源文件效果很好18年。仍然可以使用热点Java版本“ 1.8.0_333”。使用热点Java版本“ 18.0.1.1”运行,无法加载资源...所有这些都用同一JAR文件,我确实检查并包含了资源文件。

String fileName = "/images/logo.png";
ImageIcon image = new ImageIcon();

byte[] imageBytes = null;
InputStream in = image.getClass().getResourceAsStream(fileName);
if (in == null) {
  System.out.println("could not find " + fileName);
}

以上 - 代码片段。在使用18.0.1.1时,在实际上是无效的...任何人都看到了从一个版本到另一个版本的处理getResourceasstream的差异吗?

Loading resource files from a jar file (a png to build an ImageIcon) worked well for 18 years. Still works with Hotspot java version "1.8.0_333". Running with Hotspot java version "18.0.1.1" fails to load the resource... All this with the same jar file, that I did check and contains the resource file.

String fileName = "/images/logo.png";
ImageIcon image = new ImageIcon();

byte[] imageBytes = null;
InputStream in = image.getClass().getResourceAsStream(fileName);
if (in == null) {
  System.out.println("could not find " + fileName);
}

Above - code snippet. in is effectively null when using 18.0.1.1... Anyone has seen difference in processing getResourceAsStream from one version to the other ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文