java.io.IOException:不支持标记/重置 [英] java.io.IOException: mark/reset not supported

查看:26
本文介绍了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());
}

当我从 netbeans 运行应用程序时,此代码工作正常.声音播放,没有例外.但是,当我从 dist 文件夹运行它时,声音不会播放,并且在我的消息对话框中出现 java.io.IOException: mark/reset not supported.

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?

推荐答案

AudioSystem.getAudioInputStream(InputStream) 说:

该方法的实现可能需要多个解析器来检查流来确定它们是否支持它.这些解析器必须能够标记流,读取足够的数据以确定他们是否支持流,如果没有,则重置流的读取指针指向其原始值位置.如果输入流没有支持这些操作,这个方法可能会因 IOException 而失败.

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.

因此,您提供给该方法的流必须支持可选的标记/重置 功能.使用 BufferedInputStream 装饰您的资源流.

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);

这篇关于java.io.IOException:不支持标记/重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆