这是我的代码:
package JavaFactoryPatternExample;
import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class TutorialSound {
public static void main(String[] args ){
File Bird = new File("JavaFactoryPatternExample.sounds/bird.WAV");
PlaySound(Bird);
}
static void PlaySound(File Sound){
try{
Clip clip = AudioSystem.getClip();
clip.open(AudioSystem.getAudioInputStream(Sound));
clip.start();
Thread.sleep(clip.getMicrosecondLength()/1000);
}catch(Exception e){
}
}
}
答案 0 :(得分:0)
确保该文件与java程序位于同一目录中,并且您已正确命名该文件。文件名看起来很奇怪。