I have a file of information separated by commas of which I need to tokenize and place into arrays.
The file has info such as
14299,Lott,Lida,22 Dishonest Dr,Lowtown,2605
14300,Ryder,Joy,19 Happy Pl,Happyville,2701
and so forth. I need to tekonize those pieces of information of which is separated by a comma. I'm not sure how to write out the tokenizer code to make it separate. I've managed to count the amount of lines in the document with;
File customerFile = new File("Customers.txt");
Scanner customerInput = new Scanner(customerFile);
//Checks if the file exists, if not, the program is closed
if(!customerFile.exists()) {
System.out.println("The Customers file doesn't exist.");
System.exit(0);
}
//Counts the number of lines in the Customers.txt file
while (customerInput.hasNextLine()) {
count++;
customerInput.nextLine();
}
And I also have the class of which I'll be placing the tokenized info into;
public class Customer {
private int customerID;
private String surname;
private String firstname;
private String address;
private String suburb;
private int postcode;
public void CustomerInfo(int cID, String lname, String fname, String add, String sub, int PC) {
customerID = cID;
surname = lname;
firstname = fname;
address = add;
suburb = sub;
postcode = PC;
}
But after this point I'm not sure how to place the info into the arrays of the customer. I've tried this but it's not right;
for(i = 0; i < count; i++) {
Customer cus[i] = new Customer;
}
It's telling me the 'i' and the new Customer are errors as it 'can't convert Customer to Customer[]' and 'i' has an error in the token.