我試圖使用掃描儀從文本文件打印行,但它只打印第一行,然後纔打印新行,直到while循環經過文件。掃描儀nextline()只打印新行
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()以使用此代碼?