码迷,mamicode.com
首页 > 其他好文 > 详细

System.out.println()的详解

时间:2018-09-21 19:45:49      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:throw   index   vat   open   text   cat   read   closeable   system类   

System是System类

1 package java.lang;
2 public final class System {
3       public final static PrintStream out = null;
4 }

println()是PrintStream 类中的方法。

package java.io;
public class PrintStream extends FilterOutputStream
    implements Appendable, Closeable
{
  
   protected OutputStream out;

   private BufferedWriter textOut;

    private void ensureOpen() throws IOException {
       if (out == null)
        throw new IOException("Stream closed");
    }

   
public void println() { newLine();//换行 } public void println(boolean x) { synchronized (this) { print(x); newLine(); } } public void println(String x) { synchronized (this) { print(x); newLine(); } } public void print(boolean b) { write(b ? "true" : "false"); } public void print(Object obj) { write(String.valueOf(obj)); } private void write(String s) { try { synchronized (this) { ensureOpen(); textOut.write(s); textOut.flushBuffer(); charOut.flushBuffer(); if (autoFlush && (s.indexOf(‘\n‘) >= 0)) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } private void newLine() { try { synchronized (this) { ensureOpen(); textOut.newLine(); textOut.flushBuffer(); charOut.flushBuffer(); if (autoFlush) out.flush(); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); } catch (IOException x) { trouble = true; } } }

 

System.out.println()的详解

标签:throw   index   vat   open   text   cat   read   closeable   system类   

原文地址:https://www.cnblogs.com/stujike/p/9688054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!