简体   繁体   English

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

[英]Is System.out buffered or unbuffered?

Is System.out buffered or unbuffered? System.out是缓冲还是非缓冲?

I read this is an object of InputStream and PrinterStream is the type of object referenced by System.out . 我读到这是InputStream一个对象,而PrinterStreamSystem.out引用的对象类型。

And they Both are Unbuffered so Why println() flushes the unbuffered...is it possible to flush unbuffered and I have read they are written immediately. 并且它们都是无缓冲的,所以为什么println()刷新无缓冲的...是否可以刷新无缓存并且我已经读过它们是立即写入的。

System.out is the "standard" output. System.out是“标准”输出。 On most operating systems that terminal io is buffered, and paging is supported. 在大多数操作系统上 ,终端io被缓冲,并且支持分页。

From the Javadoc, 来自Javadoc,

The "standard" output stream. “标准”输出流。 This stream is already open and ready to accept output data. 此流已打开并准备接受输出数据。 Typically this stream corresponds to display output or another output destination specified by the host environment or user. 通常,该流对应于主机环境或用户指定的显示输出或另一输出目的地。

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

Optionally, a PrintStream can be created so as to flush automatically; 可选地,可以创建PrintStream以便自动刷新; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte ('\\n') is written. 这意味着在写入字节数组,调用其中一个println方法或写入换行符或字节('\\ n')后,将自动调用flush方法。

System.out.println prints the argument passed, into the System.out which is generally stdout. 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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM