I am using an OutputStream
and a PrintWriter
. Here's my code:
OutputStream os = System.out;
PrintWriter writer = new PrintWriter(os, false);
writer.println("Hell");
writer.println("Hello");
writer.println("Hello");
writer.println("Hello");
writer.println("Hello");
writer.println();
os.write("45\n".getBytes(), 0, "45\n".getBytes().length);
writer.println();
writer.flush();
os.flush();
The output is:
45
Hello
Hello
Hello
Hello
Hello
Why is 45
printed before Hello
's, even though the PrintWriter
is flushed before the OutputStream
?
Edit : Please correct me If I am wrong about flushing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.