This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes getResource(fileName) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "getResource(fileName)" Watch "getResource(fileName)" New topic
Author

getResource(fileName)

sopal Pal
Ranch Hand

Joined: Aug 04, 2003
Posts: 83
Hi

In my program I am making a call as

ClassLoader.getSystemClassLoader().getResource(fileName)


If I try the above method with the filename as
viewing.proprties and that file resides in

c:\program files\

Then

This is the error I get :

------- Error ----------

url = file:/C:/Program%20Files/viewing.properties
java.io.FileNotFoundException: C:\Program%20Files\viewing.properties (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at TestFile.getProperties(TestFile.java:79)
at TestFile.main(TestFile.java:19)

--------------------------


** ANY IDEA How to resolve this

The code works fine - if there is no SPACE in the directory.
Is there a way to get around this issue

Thanks


SCEA, SCBCD, SCJP1.4, OOAD-UML, OCP 9i
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 691
    
    1
Your error example shows %20 in the path to the file. Replace that with a space. How do you get the path?

See the URLDecoder class(?) for a method to remove it.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: getResource(fileName)
 
jQuery in Action, 3rd edition