【发布时间】:2014-06-25 06:15:37
【问题描述】:
System.out 是缓冲的还是非缓冲的?
我读到这是InputStream 的对象,PrinterStream 是System.out 引用的对象类型。
而且它们都是无缓冲的,所以为什么println() 刷新无缓冲...是否可以刷新无缓冲并且我已经阅读它们是立即写入的。
【问题讨论】:
标签: java
System.out 是缓冲的还是非缓冲的?
我读到这是InputStream 的对象,PrinterStream 是System.out 引用的对象类型。
而且它们都是无缓冲的,所以为什么println() 刷新无缓冲...是否可以刷新无缓冲并且我已经阅读它们是立即写入的。
【问题讨论】:
标签: java
System.out 是“标准”输出。在大多数operating systems 上,终端io 被缓冲,并且支持分页。
来自 Javadoc,
“标准”输出流。此流已经打开并准备好接受输出数据。通常,此流对应于主机环境或用户指定的显示输出或另一个输出目的地。
【讨论】:
来自http://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html:
可选地,可以创建
PrintStream以便自动刷新;这意味着在写入字节数组、调用println方法之一或写入换行符或字节 ('\n') 后,将自动调用flush方法。
【讨论】:
System.out.println 将传递的参数打印到通常是标准输出的 System.out 中。
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.
【讨论】: