I'm not quite sure why my sound file isn't running. I'm pretty sure I have the directory correct. Currently coding in IntelliJ and saved my files in my Documents folder. Here is the code for the sound class I have to open the directory to the sound file.
private AudioClip myClip;
public Sound(String fileName){
try{
String soundDir = "." + File.separator + "a3" + File.separator + "sounds" + File.separator + fileName;
File file = new File(soundDir);
System.out.println(file);
if(file.exists()){
myClip = Applet.newAudioClip(file.toURI().toURL());
}else{
throw new RuntimeException("Sound: file not found: " + fileName);
}
}catch(MalformedURLException e){
throw new RuntimeException("Sound: malformed URL: " + e);
}
}
From what I understand the "."
goes to the root of the project folder. My project is named a3
and I have a sounds
folder saved with all the sounds under the a3
folder. I can't figure out why I keep getting "Sound: file not found:"
Current directory it's under is /Documents/School/Game/a3/...
What am I doing incorrectly?