Class.getResource中是否存在区分大小写的奇怪错误? [英] Weird case sensitivity bug in Class.getResource?

查看:44
本文介绍了Class.getResource中是否存在区分大小写的奇怪错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码加载图像资源,并且该图像资源在我的开发环境(netbeans)中运行良好,但是从桌面运行后立即抛出异常.

I was loading an image resource with the following code and it works fine from my dev environment (netbeans) but threw an exception as soon as it ran from the desktop.

new ImageIcon(Images.class.getResource("images/highlighter24.gif"));

我将其追溯到文件中大小写与代码中不同的文件.

I traced it down to my file having different case than in the code.

好,我不好,但是为什么行为不一致?

Fine, my bad, but why the inconsistent behavior?

格林姆林斯?

注意:在您询问之前,我正在Windows上运行.

Note: I'm running on windows before you ask.

推荐答案

让我猜:在NetBeans中,它是从文件系统加载的(不区分大小写),而从桌面运行时,它是在jar中文件(区分大小写).

Let me guess: in NetBeans it was loading it from the file system (which is case-insensitive) whereas when running it from the desktop it was in a jar file (which is case-sensitive).

我以前见过这种情况,因为Web应用程序在Windows上运行良好,但在Unix上却失败了,因为我们在URL中输入了错误的大小写.

I've seen this kind of thing before, where a web app worked fine on Windows but failed on Unix because we'd got the case wrong in the URL.

如果您将jar文件视为仅仅是另一个文件系统",那么即使有一些不一致之处也很烦人.

If you think of jar files as "just another file system" then it makes sense, even if it's slightly annoying to have the inconsistency.

这篇关于Class.getResource中是否存在区分大小写的奇怪错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆