Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class.getResource(path) not working ??  RSS feed

 
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: 21044
85
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!