https://luckytoilet.wordpress.com/2010/05/21/how-system-out-println-really-works/


How System.out.println() really works



System.java


public final static PrintStream out = nullPrintStream();





private static PrintStream nullPrintStream() throws NullPointerException {

if (currentTimeMillis() > 0) {

return null;

}

throw new NullPointerException();

}



FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);

setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));



JNIEXPORT void JNICALL

Java_java_lang_System_setOut0(JNIEnv *env, jclass cla, jobject stream)

{

jfieldID fid =

(*env)->GetStaticFieldID(env,cla,"out","Ljava/io/PrintStream;");

if (fid == 0)

return;

(*env)->SetStaticObjectField(env,cla,fid,stream);

}





.....




대충 넘기고.. 결국..




A tour through java.io




public void println(String x) {

synchronized (this) {

print(x);

newLine();

}

}



public void print(String s) {

if (s == null) {

s = "null";

}

write(s);

}



private void write(String s) {

try {

synchronized (this) {

ensureOpen();

textOut.write(s);

textOut.flushBuffer();

charOut.flushBuffer();

if (autoFlush && (s.indexOf(' ') >= 0))

out.flush();

}

}

catch (InterruptedIOException x) {

Thread.currentThread().interrupt();

}

catch (IOException x) {

trouble = true;

}

}




걍 그후는 링크가서 봐라.

ㅇㅇ