My sound file doesn't in a .jar file

My sound in my game will only play if a folder titled res is in the same directory as the .jar file. The res folder is already a source folder in the .jar file here is my code

try {
		     InputStream defaultSound = Game.class.getResourceAsStream("/res/TrailsGameMusic.wav");
		     // getClass().getSy.getResource("/images/ads/WindowsNavigationStart.wav");
		    
		     System.out.println("defaultSound " + defaultSound);  // check the URL!
		     AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(defaultSound);
		     Clip clip = AudioSystem.getClip();
		     clip.open(audioInputStream);
		     clip.loop(Clip.LOOP_CONTINUOUSLY);
		} catch (Exception ex) {
		     ex.printStackTrace();
		}

Remove the “/res” part so it just becomes “/TrailsGameMusic.wav”

Now i dont have sound

But is it able to find the file?

Only when it isnt in a jar file
It just doesn’t play as a jar

It isn’t found either

Use this helper-class to find the appropriate way to find your resource.

Are you packing the resources into the jar file?

yes

What is the output of the helper-class?

It tells me that I am doing it correctly and that is should work

[ClassLoaderDummy] SEARCHING: “/TrailsGameMusic.wav”
[ClassLoaderDummy] FOUND: mislocated resource:
[ClassLoaderDummy] “TrailsGameMusic.wav”
[ClassLoaderDummy] in classpath entry:
[ClassLoaderDummy] “C:\Users\Ciro\Desktop\Trails\Trails.jar”
[ClassLoaderDummy] for access use:
[ClassLoaderDummy] getResourceAsStream("/TrailsGameMusic.wav");
defaultSound sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@8938a9
java.io.IOException: mark/reset not supported
at java.util.zip.InflaterInputStream.reset(Unknown Source)
at java.io.FilterInputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.GamerC4.main.Game.(Game.java:102)
at com.GamerC4.main.Game.main(Game.java:260)

[quote=“GamerC4,post:11,topic:55982”]
Just wrap the InputStream in a BufferedInputStream prior to passing it to the AudioSystem:


InputStream defaultSound = Game.class.getResourceAsStream("/TrailsGameMusic.wav");
+ defaultSound = new BufferedInputStream(defaultSound);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(defaultSound);

Thank you
If I can do something to return the favor, let me know