I was trying to write a piece of Java code to read each line from a file and add it to an Arraylist. Here is my code:
// try catch block removed for clarity.
file = new TextFileIn("names.txt");
String line = null;
while ((line = file.readLine()) != null) {
list.add(line);
}
names.txt
was located in the same package folder as my code. The IDE I used was Eclipse. When I run the code however I got a FileNotFoundException
. The TextFileIn
class comes from http://www.javaranch.com/doc/com/javaranch/common/TextFileIn.html
How could I get the file to be found?