java中io异常是啥,java.io.IOException异常:标志/复位不支持

try {

//String location = dir1.getCanonicalPath()+"\\app_yamb_test1\\mySound.au";

//displayMessage(location);

AudioInputStream audio2 = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("mySound.au"));

Clip clip2 = AudioSystem.getClip();

clip2.open(audio2);

clip2.start();

} catch (UnsupportedAudioFileException uae) {

System.out.println(uae);

JOptionPane.showMessageDialog(null, uae.toString());

} catch (IOException ioe) {

System.out.println("Couldn't find it");

JOptionPane.showMessageDialog(null, ioe.toString());

} catch (LineUnavailableException lua) {

System.out.println(lua);

JOptionPane.showMessageDialog(null, lua.toString());

}

This code works fine when I run the application from netbeans. The sound plays and there are no exceptions. However, when I run it from the dist folder, the sound does not play and I get the java.io.IOException: mark/reset not supported in my message dialog.

How can I fix this?

解决方案

The implementation of this method may

require multiple parsers to examine

the stream to determine whether they

support it. These parsers must be able

to mark the stream, read enough data

to determine whether they support the

stream, and, if not, reset the

stream's read pointer to its original

position. If the input stream does not

support these operation, this method

may fail with an IOException.

Therefore, the stream you provide to this method must support the optional mark/reset functionality. Decorate your resource stream with a BufferedInputStream.

//read audio data from whatever source (file/classloader/etc.)

InputStream audioSrc = getClass().getResourceAsStream("mySound.au");

//add buffer for mark/reset support

InputStream bufferedIn = new BufferedInputStream(audioSrc);

AudioInputStream audioStream = AudioSystem.getAudioInputStream(bufferedIn);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值