Hello I have this in my code
File file = new File("words.txt");
Scanner scanFile = new Scanner(new FileReader(file));
ArrayList<String> words = new ArrayList<String>();
String theWord;
while (scanFile.hasNext()){
theWord = scanFile.next();
words.add(theWord);
}
But for some reason I am getting a
java.io.FileNotFoundException
I have the words.txt file in the same folder as all of my .java files
What am I doing wrong? Thanks!
java.io.FileReader.FileReader( java.io.File )states that aFileNotFoundExceptionis thrown "if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading." If you're sure the file exists and that it's a regular file, then there must be some reason it can't be opened. Make sure the file's permissions allow for reading as well.