File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading within a sub-folder using ImageIcon ?

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know whether I can set ImageIcon to read from a relative path, rather, than from the same path where the source code resides. For example my images are located within an images sub-directory relative to the source code. If there is some other way I don't mind knowing either

The following code does not compile it is just to illustrate what I would like to do:


 
Stephan van Hulst
Bartender
Pie
Posts: 4843
34
Chrome Netbeans IDE Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use Class.getResource() to get resources relative to the class path.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on a path relative to the JVM's current directory isn't really the way to go.
Indeed, classpath resources a better alternative, and there are several ways to go about this.
For instance, using the relevant methods on Class and ClassLoader.
These differ slightly in their behavior though, which can be a bit of a pain.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic