【发布时间】:2014-10-17 23:26:45
【问题描述】:
我有一个用逗号分隔的信息文件,我需要对其进行标记并放入数组中。
该文件包含诸如
之类的信息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;
}
它告诉我“i”和新客户是错误的,因为它“无法将客户转换为客户[]”并且“i”在令牌中有错误。
【问题讨论】:
-
Java 还是 Javascript?您的问题可能只有其中一个标签。
标签: java arrays eclipse class token