# Load sounds with an array of SoundFile

**URL:** <https://discourse.processing.org/t/load-sounds-with-an-array-of-soundfile/2659>\
**Category:** Coding Questions\
**Created:** [August 15, 2018, 10:50am UTC](https://discourse.processing.org/t/load-sounds-with-an-array-of-soundfile/2659 "2018-08-15T10:50:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.processing.org/u/math)\
**Post date:** [August 15, 2018, 10:50am UTC](https://discourse.processing.org/t/load-sounds-with-an-array-of-soundfile/2659/1 "2018-08-15T10:50:12Z")

</div>

I try to load multiple sounds with an array of SoundFile, but I keep getting a `Error: Soundfile doesn't exist. Pleae check path` when I try to initalize the array.

Here’s my function (I want it to return a SoundFile array in order to give it to an object):

```auto
SoundFile[] loadSoundFiles(String path, String[] fileList) {
  SoundFile[] soundFile = new SoundFile[fileList.length]; // initialize the array
  for (int i=0; i<fileList.length; i++) {
    soundFile[i] = new SoundFile (this, path + "/" + fileList[i]);
  }
  return soundFile;
}

```

The error seems to be on this line:

`SoundFile[] soundFile = new SoundFile[fileList.length]`

`fileList` contains the file names, for example: `{"file0.wave", "file2.wav}`

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [August 15, 2018, 4:19pm UTC](https://discourse.processing.org/t/load-sounds-with-an-array-of-soundfile/2659/2 "2018-08-15T16:19:03Z")

</div>

For me it works if called like this:

```auto
void setup() {
  sounds = loadSoundFiles("../data", new String[] {"vibraphon.aiff"});
  printArray(sounds);
  sounds[0].play();
}      

```

The default path seems to be `data/` so I need to specify `../data` to go one level up, then back into data, then find the files there. If I specify `data` instead of `../data`, it’s probably looking for `data/data/vibraphon.aiff` which returns the error you mention.

---

<div class="post-metadata">

**Author:** ![math](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@math](https://discourse.processing.org/u/math)\
**Post date:** [August 16, 2018, 9:18am UTC](https://discourse.processing.org/t/load-sounds-with-an-array-of-soundfile/2659/3 "2018-08-16T09:18:52Z")

</div>

Thank you for the answer! Actually my code was working, the error was because I made a typo on the “path” variable… And I didn’t need to specify the `data` folder.

Le mer. 15 août 2018 à 18:29, aBe [processingfoundation1@discoursemail.com](mailto:processingfoundation1@discoursemail.com) a écrit :
