import java.io.*;
import javax.sound.sampled.*;
public class Test {
public static void main(String[] args) throws Exception {
AudioSystem.getAudioFileFormat(new File(
"myaudio.wav"));
AudioSystem.getAudioFileFormat(new FileInputStream(
"myaudio.wav"));
}
}
输出:
Exception in thread "main" java.io.IOException: mark/reset not supported
at java.io.InputStream.reset(InputStream.java:330)
at com.sun.media.sound.WaveFileReader.getAudioFileFormat(WaveFileReader.java:88)
at javax.sound.sampled.AudioSystem.getAudioFileFormat(AudioSystem.java:985)
at Test.main(Test.java:10)
@EDIT
根据 @René Jeschke
、@Phil Freihofner
和 @Andrew Thompson
的答案,在 Java Sound API
与 IO 流
进行交互时,无论在何处都需要使用 mark/reset
作为强制协议。在我看来,应该把 buffered
流的类型而不是 raw
流的类型特别定义为要传递的参数的签名。这样做将产生比任意接受 IO 流
然后诉诸于 IOException
作为不良指标更可取的结果。