Weird case sensitivity bug in Class.getResource?

依然范特西╮ 提交于 2020-08-27 04:41:13

问题


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?

Gremlins?

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


回答1:


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).

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.

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.



来源:https://stackoverflow.com/questions/234990/weird-case-sensitivity-bug-in-class-getresource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!