Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading image file from executable jar

 
Mihai Popa
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have built a small Swing application that wants to resemble to a GIS application.

There is a problem when i try to load an image file (jpg):
-When i run the project from Eclipse, loading a larger image (18000 px) using "ImageIO.read(new File(...))" takes 3 second and starts the fan of my computer.
Anyway, the image is loaded succesfully
-When i try to do this from an exported "runnable jar" of my app, the image doesn't load anymore. The "runnable jar" loads correctly smaller images.

Can you tell me what is the problem?
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For files inside ZIP or JAR files, you can no longer use java.io.File and its matching stream / reader / writer classes. Instead, you should use Class.getResource, Class.getResourceAsStream, or the same methods from ClassLoader.
 
Paul Clapham
Sheriff
Posts: 21148
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Brass,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic