-1

I made a program to read audio files. At first I did it with absolute path because it's easyer to develop.
Then I cahnge it to relative path because I want to compress it to a *jar. So I code this method(at first only short later the code:

1.: at first I make a FileArray to save the Files
2.: make the array to save the AudioClip
3.: for loop to read the Clips

Now the code:

    private AudioClip[] liesAudioDateien (File inputFile) {
        File[] dateFileArray;
        AudioClip[] tracks;
        dateFileArray = inputFile.listFiles();
        tracks = new AudioClip[dateFileArray.length];
        for (int i = 0; i < tracks.length; i++) {
            if (dateFileArray[i].isFile()) {
                try {
                    tracks[i] = Applet.newAudioClip(dateFileArray[i].toURL());
                } catch (IOException ex) {
                    System.err.println("Error!: -- " + ex.toString());
                }
            }

        }
        return tracks;   
    }

inputFile.listfiles() returns null, as seems my path isn't OK. But my path is Ok, because I let it print on the command line. D:\Eclipse\MyProjekt\dist\MyProject.jar\audio. In NetBeans, it does work. If I make a jar file, it doesn't work.

I have already try:

  1. D:\Eclipse\MyProjekt\dist\MyProject.jar\audio\
  2. / in place of \
eightShirt
  • 1,457
  • 2
  • 15
  • 29
Hydroid
  • 119
  • 3
  • 16

1 Answers1

1

Are you sure this is the correct file path?

D:\Eclipse\MyProjekt\dist\MyProject.jar\audio

The audio directory is in a folder called MyProject.jar?

If your audio files are within the .jar file you cannot use the File class to list them. What you have to do instead is read the entries from the .jar file, like in this question.

Community
  • 1
  • 1
Joni
  • 108,737
  • 14
  • 143
  • 193
  • My jar file call MyProjekt.jar. It is wrong? In Myprojekt.jar containes 'audio, source, images' – Hydroid Mar 24 '13 at 18:29