我曾嘗試搜索關於此的任何可能的問題,分配全線飄紅,但沒有似乎正是我Java的閱讀文本文件和字符串
在這裏工作的一些代碼,我已經閱讀在所有文件子目錄,該方法需要的文件名來尋找和其目錄
public static Account FileRead(String fname, String dir) throws blankException {
File file = new File(dir + fname);
try {
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String type = sc.nextLine();
if (type.equals("S") || type.equals("C")) {
String pin = sc.nextLine();
double balance = sc.nextDouble();
String name = sc.next();
String address = sc.next();
String date = sc.next();
if (type.equals("S")) {
return new SavingAccount(pin, balance, name, address, date);
}
if (type.equals("C")) {
return new CheckingAccount(pin, balance, name, address, date);
}
throw new blankException("no account type given");
}
}
sc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}//end file reader
我的問題是,地址,掃描儀只需要弗里斯特「字」,在該文件中的地址是「1234房子驅動器「,地址只有1234.how我可以在哪裏地址是」1234房屋驅動器「
還,所有文件都是這種格式
type
pin
balance
name
address
date
只需使用'Scanner#nextLine()'並分別讀取每行輸入。 –