how BufferReader reading empty lines

 

Questions


I am entering lines from input (IDE eclipse Luna) on pressing enter the cursor keeps moving down but no output shows up. In tried second method but i have to press enter twice to print output how can i fix both errors . Why in second method as soon as it detects blank line it doesn’t print why i have to press enter twice And what commands goes when we press enter in console

FIRST METHOD

private static String para = null;
public static void main(String[] args) throws IOException {
    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(System.in));
    String line;
    while ((line = bufferedReader.readLine()) != null) {
        para = para + line;
    }
    bufferedReader.close();
    System.out.println(para);
}

SECOND METHOD

String line;
    while (!(line = br.readLine()).equals("")) {
        s1 = line.split(" ");
        for (int j = 1; j < s1.length; j++) {
            int m = Integer.parseInt(s1[j]);
            edges[Integer.parseInt(s1[0]) - 1].add(vertices[m - 1]);
        }

    }

 

 

————————————————-

Answer

bufferedreader,java

Facebook Comments

Post a comment