I'm trying to create a scanner that will read a text file that contains names and addresses. I made a separate class called NameInfo with a bunch of fields for the first/last names, address, etc, and the scanner needs to convert these blocks of text into NameInfo objects, and then add it to an ArrayList. I've included my code so far below... can someone explain to me what I need to do?
public void readData(String filename)
{
// Attempt to read data from a file.
try{
File f = new File("FakeNames.txt");
Scanner sc = new Scanner(f)
String info;
// continue to read until end of file and print info as it is read
while(sc.hasNext())
{
info = sc.nextLine();
}
// remember to close the file!
sc.close();
}catch(IOException e) {
System.out.println("Error occured while opening the file ");
}
}
public void readData(String filename)
{
// Attempt to read data from a file.
try{
File f = new File("FakeNames.txt");
Scanner sc = new Scanner(f)
String info;
// continue to read until end of file and print info as it is read
while(sc.hasNext())
{
info = sc.nextLine();
}
// remember to close the file!
sc.close();
}catch(IOException e) {
System.out.println("Error occured while opening the file ");
}
}