我觉得我的代码没问题,我的.jar文件里也包含了.wav文件。但是当我尝试使用getResourceAsStream加载它时,出现了错误。
我的错误如下:
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(Unkno
wn Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at operation.MainWindowOperations.prepareAudio(MainWindowOperations.java
:92)
at operation.MainWindowOperations.<init>(MainWindowOperations.java:81)
at graphics.LaunchGraphics.<init>(LaunchGraphics.java:25)
at run.RunApp.main(RunApp.java:14)
这是我的代码:
private void prepareAudio() {
try {
InputStream is = this.getClass().getClassLoader().getResourceAsStream("beep.wav");
inputStream = AudioSystem.getAudioInputStream(is);
clip = AudioSystem.getClip();
clip.open(inputStream);
} catch (Exception ex) {
ex.printStackTrace();
}
}
有人可以帮我吗?非常感谢!