System.out是缓冲还是非缓冲?

时间:2014-06-25 06:15:37

标签: java

System.out是缓冲还是非缓冲?

我读到这是InputStream的对象,PrinterStreamSystem.out引用的对象类型。

并且它们都是无缓冲的,所以为什么println()刷新无缓冲的...是否可以刷新无缓存,我已经读过它们是立即写的。

3 个答案:

答案 0 :(得分:4)

System.out是"标准"输出。在大多数operating systems上,终端io被缓冲,并支持分页。

来自Javadoc,

  

"标准"输出流。此流已打开并准备接受输出数据。通常,该流对应于主机环境或用户指定的显示输出或另一输出目的地。

答案 1 :(得分:2)

来自http://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html

可选地,可以创建PrintStream以便自动刷新;这意味着在写入字节数组,调用其中一个println方法或写入换行符或字节('\ n')后,将自动调用flush方法。

答案 2 :(得分:1)

System.out.println将传递的参数打印到System.out中,该文件通常为stdout。

System – is a final class and cannot be inherited. As per javadoc, “…Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array…”
out – is a static member field of System class and is of type PrintStream. Its access specifiers are public final. This gets instantiated during startup and gets mapped with standard output console of the host. This stream is open by itself immediately after its instantiation and ready to accept data.
println – println prints the argument passed to the standard console and a newline. There are multiple println methods with different arguments (overloading). Every println makes a call to print method and adds a newline. print calls write() and the story goes on like that.