• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using FileInputStream with a relative location not working with JAR

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so somewhere in my rickroll application i've got a file which is rickroll.mp3 and is the argument for a fileinputstream.

Now when i test my application in eclipse everything works fine. But when i export my source to a executable jar with eclipse the sound seems to be not loaded.

I'm also using JLayer to play the mp3 file but that shouldn't matter really.

So the problem here i think is that the path when compiled doesn't really point to my file anymore.
When i check back the jar file i created, all files (images/sound) needed are there.



Here is a pic of my project



And the jar file itself



And here is the failing code in my MP3.java at line 3-4




I hope someone can help me out with what im doing wrong with the FileInputStream
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what you showed us is a picture of something in your IDE. Whereas what you should be looking at is the directory structure in the JAR.
 
bert de blonde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:But what you showed us is a picture of something in your IDE. Whereas what you should be looking at is the directory structure in the JAR.


On request i took a picture of the Jar file with 7-zip
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just noticed your code tries to use a FileInputStream. That doesn't make sense because the entry in the JAR isn't a file. Your relative URL is correct, just change from using getResource() to getResourceAsStream() and use the InputStream you get from that.
 
bert de blonde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Omg it worked, thanks a lot for helping me !!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic