• Post Reply Bookmark Topic Watch Topic
  • New Topic

class.getResource(path) not working ??

 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!