2
我有點困惑,試圖讓我的程序從文本文件中讀取。該文本文件由以下內容組成:客戶ID,客戶標題,客戶姓名,客戶姓名,客戶地址,客戶城鎮或客戶的郵政編碼,發行年份和保單號碼。其餘字段對應於策略編號所屬的策略類型。爲了將每個字段分開,我被告知DELIMITER。從文本文件刪除器導入數據
文本文件看起來像這樣:
IC-x00042W/Ms/LQ/Bethea/205, Willis Road/Bolton/BO5 1DQ/2007/C02000007/10000/0.5/2008/B27100037/150000/0.3/2011/V30200319/2000/21/1/0#
IC-x00033D/Mr/R/Bowie/119, Thatcher Way/Glasgow/GL9 5SX/2008/L09000016/50000/45/2/2009/C74100008/8000/0.6/2012/B05300001/125000/0.5#
IC-x00013A/MS/GRV/Blackwell/209, Drunk Road/Hawick/HK8 1MY/2013/B09000009/225000/0.1/2011/C14100014/20000/0.1/2010/V63200304/12000/43/5/1#
到目前爲止,我有東西,看起來像這樣:(有一類稱爲名稱包含了所有客戶的個人信息,幷包含所有一類叫做地址地址詳細信息):
final String CLIENT_DELIMITER = "#";
final String ITEM_DELIMITER = "/";
Scanner fileScan = null;
Scanner clientScan = null;
/*
* ********************************************************************
*
* Opening the text file and reading from the text file. If the
* File cannot be read then an error is thrown
*
* ********************************************************************
*/
try {
fileScan = new Scanner(inputFile);
} catch (Exception e) {
System.out.println(e);
}
//********************************************************************
String nxtClient = null;
//Define classes
ClientDetailsList clientInfo = null;
Name clientNameDetails = null;
Address clientFullAddress = null;
PolicyList clientPolicies = null;
ClientDetailsList clientDetails = null;
ClientDetailsList clientCollection = new ClientDetailsList();
fileScan.useDelimiter(ITEM_DELIMITER);
/*
* ******************************************************************
* Scan for client details from the text file
* ******************************************************************
*/
while (fileScan.hasNext()) {
// Input the data for the next Client
nxtClient = fileScan.next().trim();
clientScan = new Scanner(nxtClient);
clientScan.useDelimiter(ITEM_DELIMITER);
//Client Variables
String clientID = null;
clientScan.useDelimiter(ITEM_DELIMITER);
String clientTitle = null;
String clientInitials = null;
String clientSurname = null;
//Reads in details from name
clientID = fileScan.next().trim();
clientTitle = fileScan.next().trim();
clientInitials = fileScan.next().trim();
clientSurname = fileScan.next().trim();
//Construct Name
clientNameDetails = new Name(clientTitle, clientInitials, clientSurname);
String clientAddress = null;
String clientTownOrCity = null;
String clientPostCode = null;
String policyDetails = null;
//Reads in details from address
clientAddress = fileScan.next().trim();
clientTownOrCity = fileScan.next().trim();
clientPostCode = fileScan.next().trim();
//Construct Address
clientFullAddress = new Address(clientAddress, clientTownOrCity, clientPostCode);
你有什麼問題? – 2013-03-10 16:54:57
我的程序無法從文本文件中讀取。到達ITEM DELIMITER時發生錯誤。我不確定這是爲什麼? – 2013-03-10 16:57:56
哪個錯誤。它有一個錯誤消息。閱讀。或者粘貼在這裏。 – 2013-03-10 16:58:42