这是从 .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
^