Print() vs Write() method of System.out

梦想的初衷 提交于 2019-12-02 11:03:06

As per the java docs of PrintStream#write

Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked.

So just call flush.

Call System.out.flush(); after System.out.write('a');.

Alternately,

As the docs suggest, set the output stream to autoflushable and then write a new line char at the end of your program. In fact the PrintStream object System.out is already set to autoflushable if you look at the source code System class. So really, all you need to do is just print a new line character in the end. No need to call flush.

System.out.print('a');
System.out.write('a');
System.out.write('\n');
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!