PrintWriter and BufferedReader

Discussion in 'Programming' started by Proof, May 19, 2015.

  1. Proof


    Does anyone know why when I do Printwriter.write("string") then do BufferedReader.readLine(), it hangs(I have a while(BufferedReader.ready()) check), but when I do PrintWriter.println("string") then BufferedReader.readLine() it works. Can someone explain to my why this is the case?
  2. PrintWriter#write does NOT write a whole line, while PrintWriter#println does.

    In other words, using
    write('h') write('e') print('l') write('l') print('o')
    will return in "hello" (no line break).

    println('h') println('e') println("llo")

    will return in


    As BufferedReader#readLine reads until a line break, it waits until you use println or write the line break yourself (write(System.lineSeperator) or similar)
    • Informative Informative x 1
  3. Proof


    Thanks for the explanation :). My guess that readLine only reads something with a line break was right.