java项目导出jar包运行时出现异常:java.io.IOException: mark/reset not supported

导致异常的代码:

AudioInputStream aisStream = 
       AudioSystem.getAudioInputStream(Sound.class.getResourceAsStream(strPath));

官方文档关于 AudioSystem.getAudioInputStream(InputStream)的说明:

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.

也就是说,为这个方法提供的流必须支持mark/reset (标记/重置)功能,解决方法是用BufferedInputStream把原来的流包一层,修改后的代码如下:

InputStream audioSrc= Sound.class.getResourceAsStream(strPath);
   InputStream bufferedIn=new BufferedInputStream(audioSrc);
   AudioInputStream aisStream = 
       AudioSystem.getAudioInputStream(bufferedIn);

参考:http://www.itkeyword.com/doc/0860229578511812x277/java-io-ioexception-mark-reset-not-supported

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值