I am making a small game in Java. For this game I just added sounds. So I want to have all my images and audio files in the jar. For pictures this was easy:
new ImageIcon(Main.class.getResource("images/machgd2.png")).getImage()
But for audio it only works when I run the program in Eclipse but not from a jar. I use:
File soundFile = new File(Main.class.getResource(filename).getFile());
So how can I get this file from inside the .jar file?
Update:
OK, got it working, thanks to Andrew! To play the sound I used a class I found on the net, and I found out that class just uses File to get an AudioInputStream, so I dropped the File thing.