0

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?

user2318083
  • 567
  • 1
  • 8
  • 27
  • Sorry I'm not really understanding what you'd like to know. Under my `Game` folder there's a `src` and `out` the `src` has all the `.java.` files and the `out` folder has all the `.class` files. @xerx593 – user2318083 Apr 22 '15 at 03:11
  • Replacing relative path with absolute path will fix your problem. – xerx593 Apr 22 '15 at 03:34

1 Answers1

0

"." just means current directory in Unix.

From within your class, use one of the techniques listed here to get the current working directory, and find out where you are wrong:

Getting the Current Working Directory in Java

Community
  • 1
  • 1
knopch1425
  • 709
  • 6
  • 19