Why line 2 not printed? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Why line 2 not printed?

Why only line 1 printer to the output screen(System.out)? The auto flush feature flushes the buffer every time I write to it right? Or am I right? https://code.sololearn.com/cw311m7I8nRM/?ref=app

3rd Dec 2021, 4:36 AM
Rishi
Rishi - avatar
3 Respuestas
+ 2
Rishi, Haven't been playing with this `PrintWriter` yet. But having read this https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html I'm getting an impression that write() method rather stores its argument into the internal buffer rather than sending it to the destination (System.out in your code) the way println() do. I get an output if I add either one of these after line 8 pw.println(); // <- no argument pw.flush();
3rd Dec 2021, 4:43 PM
Ipang
+ 3
Ipang zemiak Thank you. I thought the auto flush feature was applicable to all the writing functions of PrintWriter, but only println, printf, and format functions are applicable to the autoflush function. Thanks again 😄
4th Dec 2021, 2:08 AM
Rishi
Rishi - avatar
+ 2
do flush() after
3rd Dec 2021, 4:36 PM
zemiak