我正在尝试使用扫描仪打印文本文件中的行,但它只打印第一行,然后只打印新行,直到 while 循环遍历文件。
String line;
File input = new File("text.txt");
Scanner scan = new Scanner(input);
while (scan.hasNext()) //also does not work with hasNextLine(), but additional error
{
line = scan.nextLine();
System.out.println(line);
//other code can see what is in the string line, but output from System.out.println(line); is just a new line
}
如何让 System.out.println() 使用此代码?