我有一個由逗號分隔的信息文件,我需要對它進行標記並放入數組。如何標記文件並將數據輸入到數組中?
該文件具有信息,如
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