gpt4 book ai didi

java - 为什么在使用Eclipse IDE播放.wav声音文件时出现此错误?

转载 作者:行者123 更新时间:2023-12-03 02:24:44 25 4
gpt4 key购买 nike

每当我尝试使用ECLIPSE IDE播放.wav或.mp3声音文件时,都会得到
此错误,检查代码(这很简单,为什么我会得到错误?):

import sun.audio.*;
import java.io.*;
public class Sound {
String Filename = "someSound.wav";
InputStream in;
AudioStream as;

public Sound() {
try {
in = new FileInputStream(Filename);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
as = new AudioStream(in);
} catch (IOException e) {
e.printStackTrace();
}
AudioPlayer.player.start(as);
AudioPlayer.player.stop(as);

}

static public void main(String[] args) {
Sound s = new Sound();
}}

这是一个异常(exception):
java.io.FileNotFoundException: someSound.wav (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at Sound.<init>(Sound.java:14)
at Sound.main(Sound.java:10)
Exception in thread "main" java.lang.NullPointerException
at sun.audio.AudioStream.<init>(AudioStream.java:65)
at Sound.<init>(Sound.java:19)
at Sound.main(Sound.java:10)

所以有什么问题?

编辑1:

我也试图改变路径
C:\ Users \ Rev3rse \ workspace \ Project1 \ src \ someSound.wav

我得到了不同的检查:
java.io.IOException: could not create audio stream from input stream
at sun.audio.AudioStream.<init>(AudioStream.java:82)
at Sound.<init>(Sound.java:16)
at Sound.main(Sound.java:26)

最佳答案

FileInputStream期望使用双斜杠对文件路径进行分区,因此不要将源路径指定为C:\ Users \ Rev3rse \ workspace \ Project1 \ src \ someSound.wav使用双斜杠进行分区。

希望成功!!!

关于java - 为什么在使用Eclipse IDE播放.wav声音文件时出现此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6715384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com