• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using FileInputStream with a relative location not working with JAR  RSS feed

 
bert de blonde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Paul Clapham
Sheriff
Posts: 22505
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 22505
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!