关于PrintWriter的println()和write()方法区别

查看源代码会发现其实println()方法最终就是调用的write()方法,但是如果new PrintWriter的时候设置atutoFlush参数为true后,就会不太一样。即:

PrintWriter pw = new PrintWriter(new OutputStream(),true);

调用pw.println(“message”)方法后会自动flush,但是调用pw.write(“message”)方法后如果不close或者手动flush,是不会自动flush的。

参考链接:

https://blog.csdn.net/b11ght/article/details/6570823

https://blog.csdn.net/lutinghuan/article/details/5792004

猜你喜欢

转载自my.oschina.net/qimhkaiyuan/blog/1810529