我有以下代码尝试加载音库。我已经使用 JRE 1.6.03 和 1.6.43 在 Windows 7 上测试了代码。旧版本的 JRE (1.6.03) 工作正常,但新版本抛出异常。这是怎么回事?
public Main() {
try {
Synthesizer synth = MidiSystem.getSynthesizer();
synth.open();
BufferedInputStream soundBankStream = new BufferedInputStream(
getClass().getClassLoader().getResourceAsStream(
"soundbank.gm"));
synth.loadAllInstruments(MidiSystem.getSoundbank(soundBankStream));
} catch (MidiUnavailableException e) {
e.printStackTrace();
} catch (InvalidMidiDataException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
.
F:\>java -version
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_03-b05, mixed mode)
F:\>java -jar Test2.jar
F:\>"C:\Program Files\Java\jre6\bin\java.exe" -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
F:\>"C:\Program Files\Java\jre6\bin\java.exe" -jar Test2.jar
javax.sound.midi.InvalidMidiDataException: cannot get soundbank from stream
at javax.sound.midi.MidiSystem.getSoundbank(Unknown Source)
at com.gulshansingh.test.Main.<init>(Main.java:24)
at com.gulshansingh.test.Main.main(Main.java:14)
您可以从这里下载音库:http ://www.oracle.com/technetwork/java/soundbanks-135798.html