Read input line by line

前端 未结 3 1391
面向向阳花
面向向阳花 2021-02-18 22:59

How do I read input line by line in Java? I searched and so far I have this:

import java.util.Scanner;

public class MatrixReader {
    public static void main(S         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 00:01

    Ideally you should add a final println() because by default System.out uses a PrintStream that only flushes when a newline is sent. See When/why to call System.out.flush() in Java

    while (input.hasNext()) {
        System.out.print(input.nextLine());
    }
    System.out.println();
    

    Although there are possible other reasons for your issue.

提交回复
热议问题