我有一个由逗号分隔的信息文件,我需要对它进行标记并放入数组。如何标记文件并将数据输入到数组中?
该文件具有信息,如
14299,Lott,Lida,22 Dishonest Dr,Lowtown,2605
14300,Ryder,Joy,19 Happy Pl,Happyville,2701
等等。我需要将这些由逗号分隔的信息进行tekonize。我不知道如何写出令牌生成器代码来使它分开。我设法计算了文档中的行数;
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();
}
而且我也有我将放置标记化信息的类;
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;
}
但在此之后,我不知道如何将信息放入客户的数组。我试过这个,但是不对;
for(i = 0; i < count; i++) {
Customer cus[i] = new Customer;
}
它告诉我“我”和新的客户是错误的,因为它“不能客户转化为客户[]”和“我”在标记的错误。
的Java或Javascript?你的问题可能只有其中一个标签。 – jfriend00 2014-10-17 23:33:05