getResource Path question.

Hi,

I have an app thats been running for a long time over a 1.3.1 jvm and recently I had to upgrade the server to tomcat 5.0 and a 1.4.2 jvm. Whenever I needed to load a properties file I use

properties.load(new FileInputStream(getClass().getResource("whatever.filename").getFile()));

As I said this has worked forever but now it is failing because the path returned by the getFile method is replacing the spaces with %20 and the FileInputStream doesnt seem to like this. I know I can fix it by using URLDecoder or something similar but I was hoping to avoid having to go through the entire app and change every use of the getResource function. Is this a change in the way java returns the path from 1.3.1 to 1.4.2 or is there a setting in a ini file or something that the jvm might be using.

Thanks in advance.

[901 byte] By [Katarn321a] at [2007-10-2 2:07:45]
# 1
why not use getResourceAsStream?since a stream is what you'll need in the end anyway ...
jsalonena at 2007-7-15 19:49:08 > top of Java-index,Java Essentials,Java Programming...
# 2
... or URL.openStream(), if you want to separate getting the URL and openning the stream.
malcolmmca at 2007-7-15 19:49:08 > top of Java-index,Java Essentials,Java Programming...
# 3

Those are both good fixes and probably better than using URLDecoder but I was hoping to avoid having to change the code at all if possible. I guess my biggest question is why did the code work at all under the old tomcat and 1.3.1 jvm and was the behavior something that was configurable with jvm command line switches or settings in a ini file or something.

Thanks.

Katarn321a at 2007-7-15 19:49:08 > top of Java-index,Java Essentials,Java Programming...
# 4
No way to fix it without modifying your code. The new behaviour is a side effect of a bug fix. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4466485
jsalonena at 2007-7-15 19:49:08 > top of Java-index,Java Essentials,Java Programming...
# 5

Thanks jsalonen,

That clears up why it changed. Seems this bug/design change (depending on what side of the fence your on) sure ticked a lot of people off. Guess i'll be changing my code now. The app im working on only has a few areas where this change will need to be made. Other people in my shop work on a much bigger app and I dont think they even know of this problem yet.

Thanks all.

Katarn321a at 2007-7-15 19:49:08 > top of Java-index,Java Essentials,Java Programming...