我目前正在创建一个err ...烦人的程序,它会反复播放ding声音,但每当我运行它时都会出现错误。我已经尝试了一切,并且文件在正确的位置。这里是我当前的代码:Java.io.FileNotFoundException对于那里的文件
public class PlaySound {
public static void main(String[] args) throws Exception {
while (true) {
String path = PlaySound.class.getProtectionDomain().getCodeSource().getLocation().getPath().replaceAll("%20", " ");;
InputStream in = new FileInputStream(path + "//src//ding.wav");
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
TimeUnit.SECONDS.sleep(1);
}
}
}
是的,我已经使用了代码的其他格式,如//src//ding.wav
任何帮助,将不胜感激。
编辑:也是错误是
Exception in thread "main" java.io.FileNotFoundException: C:\Users\*** ******\Desktop\ding.jar\src\ding.wav (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at net.lookatthis.PlaySound.main(PlaySound.java:19)
EDIT2:错误是老年人之前我重命名的文件。我改变了错误,以反映当前的文件名
你能提供System.out.println(path)的输出吗? – user681574
什么是您要查找的文件:hit.wav或ding.wav? – freedev