I have this BogoSort project that I am working on, and it includes a readFromFile method to populate the ArrayList that will then be sorted in another method. I have imported both the File and Scanner class to my project, but I get an error when creating the Scanner object using the file as the parameter it tells me "file cannot be resolved to a variable", and when I try to scan the ints into variables and lists it says the scanner object cannot be resolved.
`private void readFromFile(String str) {
try {
File file = new File(str);
} catch (FileNotFoundException e) {
System.out.println("File does not exist!");
System.exit(0);
}
Scanner inFS = new Scanner(file);
randomSeed = inFs.nextInt();
String flush = inFs.nextLine();
String list = inFs.nextLine();
String[] arrOfNums = list.split(",");
for (int i = 0; i<arrOfNums.length; i++) {
input.add(Integer.parseInt(arrOfNums[i]));
}
inFs.close();
}
`
I'm expecting it to populate the randomSeed variable using the number on the first line of the file, then flush it out to move onto the list of numbers separated by commas, which then are populated into the list For example, the file would look like this:
340 \n 14,243,2,421,12,245,35,21,1,0