File I/O Inside JAR

I am trying to play a sound in my program, using AudioInputStream. However, my program is in a JAR file, so the sound that I want to play "sound.wav" is also in that file. When I run the following line, I have a File I/O exception:

AudioInputStream stream = AudioSystem.getAudioInputStream(new File("sound.wav"));

However, when I put sound.wav in the same directory as the JAR file, the sound plays and everything is OK. Is there any way to play the sound from inside the JAR?

[554 byte] By [xlogyza] at [2007-10-3 4:34:22]
# 1
Try using the other AudioSystem static method getAudioInputStream(InputStream)The InputStream argument can be obtained from Class.getResourceAsStream(String)
pbrockway2a at 2007-7-14 22:38:01 > top of Java-index,Java Essentials,Java Programming...
# 2

Note that while a jar is a file, it has a special internal organization. Java's file I/O handles files but does not know anything about the internal organization of a jar - and it can't access the contents. For that you must use some method that does know about the "special internal organization". Giving the name of something within the jar to Java's file I/O is meaningless.

ChuckBinga at 2007-7-14 22:38:01 > top of Java-index,Java Essentials,Java Programming...