Can someone help me use the Scanner in Java?

mple174

New member
Joined
Mar 19, 2009
Messages
1
Reaction score
0
Points
1
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 ");
}
}
 
Back
Top