文字列に行全体を割り当てることが、どれも私にここに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です。アドレスは" 1234家のドライブ "であることができます。
はまた、すべてのファイルが
type
pin
balance
name
address
date
'スキャナ#nextLine()'を使用して、入力の各行を個別に読み込みます。何らかの理由で –