I am trying to read in data from a file /sampledata/delivererList.txt and I cannot get the file to open and receive an No file or directory error each time even though it very much exists. For context im trying to retrieve information on a deliverer based on whether they are eligible to deliver, 1 or 0, and pass the information back to main function within a String array.
sampledata/delivererList.txt
1,deliverer name,666-666-6666,test
0,different deliverer,999-999-9999,alsoTest
read function
public String[] readDeliverers() {
String[] noDeliverer = {"0", "NO", "DELIVERER", "AVAILABLE"};
try {
File deliverFile = new File("sampledata/delivererList.txt");
Scanner fileReader = new Scanner(deliverFile);
if (fileReader.next().charAt(0) == '1') {
String data = fileReader.nextLine();
List<String> delivererList = Arrays.asList(data.split(","));
String[] delivererArray = new String[delivererList.size()];
int index = 0;
for (String value : delivererList) {
delivererArray[index] = value;
index++;
}
return delivererArray;
} else {
System.out.println("Error read");
}
fileReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred. NO FILE");
e.printStackTrace();
}
return noDeliverer;
}