问题
I have an swing app. Where I use wav file to make alarm. I put Alarm.wav in folder where I have *.class is bin folder. And it works. I use this code to get wav file and play it.
InputStream in;
try {
InputStream is = getClass().getResourceAsStream("Alarm.wav");
AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(is);
AudioPlayer.player.start(audioInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
But when I made in Eclipse runnable jar there is no sound in my app.
回答1:
I have similiar problem. Try use this code:
InputStream in;
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResource("Alarm.wav"));
AudioPlayer.player.start(audioInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/17436808/audio-file-in-jar-made-by-eclipse-ide