【发布时间】:2012-03-28 10:13:22
【问题描述】:
我猜我的代码没问题,我的 .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();
}
}
有人可以帮助我吗?提前非常感谢!
【问题讨论】:
-
您可以在此 [post][1] 中找到您的答案。 [1]:stackoverflow.com/questions/5529754/…
-
@EricR。 +1 该线程包含两个我不知道的潜在捷径。
-
它对我不起作用,它给了我另一个错误...流已关闭..
-
用那个解决方案我明白了,我不明白..:pastebin.com/6taaMJKG 我的代码在这里:pastebin.com/8wamm4E1 非常感谢你们;)
-
一个有趣的问题,我从中学到了一些关于流的知识。 :)
标签: java resources wav embedded-resource javasound