java.io.IOException: mark/reset not supported

2019-05-26 09:01发布

问题:

This code does not work. I took a class ready since it can be found here, but the music does not work. How can I fix this?

private void lblCliqueMouseClicked(java.awt.event.MouseEvent evt){                                     
     lblClique.setText("achou");
     musica = new Som();
     boolean repetir = false; 
     FileInputStream arquivo = null;
     try {
         arquivo = new FileInputStream("musica.mp3");
     } catch (FileNotFoundException ex) {
         Logger.getLogger(TelaProjeto.class.getName()).log(Level.SEVERE, null, ex);
     }
     musica.tocar(arquivo, repetir);
} 

回答1:

The error mark/reset not supported means the input stream you provided does not support setting a mark and resetting the stream to that mark. To achieve this, just wrap your FileInputStream inside a BufferedInputStream (see http://docs.oracle.com/javase/7/docs/api/java/io/BufferedInputStream.html)

InputStream arquivo=null;
...
arquivo=new BufferedInputStream(new FileInputStream(...));