Forums Register Login

class.getResource(path) not working ??

+Pie Number of slices to send: Send
Hi,

Hi,

I am trying to get the fallowing URL via class.getResource():
URL url = MyUtils.class.getResource(path);

The path is ok (for example: C:\Documents and Settings\chen\My Documents\My Pictures\22-03-07_1429.jpg)

But I get null url
Any advice why I can�t find the file?

Thanks
+Pie Number of slices to send: Send
Class.getResource and ClassLoader.getResource only work for properties inside the class path itself. If you have the full path you should use File, combined with its toURI().toURL() chained method to get the URL for the file. Don't use File's toURL() method, it is deprecated.
+Pie Number of slices to send: Send
Thanks
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1531 times.
Similar Threads
Locating a jar file relative to the application
Getting application realpath in java
Deleting a file. HELP!
reading within a sub-folder using ImageIcon ?
JVM for jar
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:48:16.