I have been working on a small program and I'm new to Java. But it keeps raising filenotfound exception. Here's my code:
import java.io.FileNotFoundException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* Don't forget your file header comment here!
*/
public class WordSearch {
/*
* This is how you declare constants in Java. You can now type
* 'MIN_WORD_LENGTH' anywhere you want to refer to it.
*/
private static final int MIN_WORD_LENGTH = 3;
public static void main(String[] args) throws FileNotFoundException {
// Remember, to access command-line arguments, you use args[0],
// args[1],...
// See CommandLine.java and Stdin.java in the Class Examples github for examples.
List<String> dictList= new ArrayList<>();
dictList = dictRead(args[0]);
}
public static List<String> dictRead (String filePath) throws FileNotFoundException{
Scanner dictScan = null;
dictScan = new Scanner(new File(filePath));
List<String> dictList = new ArrayList<>();
int i=0;
while (dictScan.hasNext()) {
dictList.add(i, dictScan.nextLine());
i+=1;
}
return dictList;
}
}
This I don't know why I keep getting this exception. I changed my run configuration and put TestCases/dictionary.txt as my first argument.
Here's a picture of my directory and I'm running WordSearch.java: