簡體   English   中英

System.out是緩沖還是非緩沖?

[英]Is System.out buffered or unbuffered?

System.out是緩沖還是非緩沖?

我讀到這是InputStream一個對象,而PrinterStreamSystem.out引用的對象類型。

並且它們都是無緩沖的,所以為什么println()刷新無緩沖的...是否可以刷新無緩存並且我已經讀過它們是立即寫入的。

System.out是“標准”輸出。 在大多數操作系統上 ,終端io被緩沖,並且支持分頁。

來自Javadoc,

“標准”輸出流。 此流已打開並准備接受輸出數據。 通常,該流對應於主機環境或用戶指定的顯示輸出或另一輸出目的地。

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

可選地,可以創建PrintStream以便自動刷新; 這意味着在寫入字節數組,調用其中一個println方法或寫入換行符或字節('\\ n')后,將自動調用flush方法。

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