これは、.txt 入力ファイルのテキスト行から文字と文字列を取得する「適切な方法」ですか?
Scanner scan, readLine;
System.out.print("Enter the name of your transaction file please (include .txt extension): ");
transFilename = scan.nextLine();
scan = new Scanner(new FileReader(transFilename));
while (scan.hasNext())
{
// read a whole line, then use scanner to parse
readLine = new Scanner(scan.nextLine());
code = readLine.next().toUpperCase().charAt(0);
switch (code) {
case 'A':
lineinput = readLine.next();
filename = lineinput;
System.out.println(filename);
Scanner input = new Scanner( new FileReader(filename));
break;
}
サンプル入力テキスト ファイルの読み取り:
A blahblah.txt
B
A gahgah.txt
このコード行が実行されると: lineinput = readLine.next(); その while ループの繰り返し中に、カーソルは行の先頭に戻りますか? スキャナーの「カーソル」が各行をどのように移動するかを知りたいだけです。
例: (^ はカーソル位置を表します):
A blahblah.txt
^