0

Do you know how to input a .wav file for a button click in java. this is my code.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

 String path = System.getProperty("user.dir")+File.separator;
 JOptionPane.showMessageDialog(rootPane, path);


    InputStream in;
    try {           
        in  = new FileInputStream(new File(path+"Audios\\A.wav"));
         AudioStream audios = new AudioStream(in);
        AudioPlayer.player.start(audios);

    }
    catch(Exception e){

    }

}     

in this code when you run in in the netbeans and press execute. the wav file is playing. but when i clean build the solution and press the button from the jar file. The sound is not playing. I want a good reply for this question.

  • You should print any exceptions caught, so that you'll know what has gone wrong and can fix it (`e.printStackTrace()`). Most likely, the wav file is not found at the path; you'll want to look into how to load a resource from a JAR. – FThompson Dec 02 '15 at 02:56
  • @Vulcan I already did it. There was no exception throwing. When i run the Application in the Netbeans it is working Perfectly. But when i do a clean build and try to Run the Executable Jar file. It won't Work. – Asiri Harisandu Dec 02 '15 at 05:53
  • found a way on my own. thanks anyway – Asiri Harisandu Dec 09 '15 at 02:57

0 Answers0