为什么 hasNext() False,但 hasNextLine() 是 True?
2022-08-31 16:10:28
						问题
为什么对于扫描仪对象,方法返回 true 而方法返回 false?hasNextLine()hasNext()
注意:基于输入文件,该方法按预期返回结果;似乎没有返回正确的结果。hasNext()hasNextLine()
法典
以下是我正在运行的代码,用于创建以下结果:
public void ScannerTest(Reader fileReaderObject){
    Scanner scannerObj = new Scanner(fileReaderObject);
    for(int i = 1; scannerObj.hasNext(); i++){
        System.out.println(i + ": " + scannerObj.next());
        System.out.println("Has next line: " + scannerObj.hasNextLine());
        System.out.println("Has next: " + scannerObj.hasNext());
    }
    System.out.println();
    scannerObj.close();
}
输入文件
以下是我传递给此扫描程序的文件的实际内容:
a   3   9
b   3   6
c   3   3
d   2   8
e   2   5
f   2   2
g   1   7
h   1   4
i   1   1
结果
以下是我运行代码时在控制台中打印的内容的结尾,其中包括我无法理解的部分:
25: i
Has next line: true
Has next: true
26: 1
Has next line: true
Has next: true
27: 1
Has next line: true
Has next: false
 
					 
				 
				    		 
				    		 
				    		 
				    		