Should I use System.out.println () or something else?

I've been programming in Java for a while, but I still have some burning questions on the basics. I heard that I should use System.out.println () to display data from some people, while others gave me different ideas (like PrintStream or something else). What is the best way to print to the console in Java?

+5
source share
9 answers

System.out - this is PrintStream.

If your main goal is to interact with the console, take a look java.io.Console. If your main goal is to have some kind of logging, use a logging framework such as the Java logging API or log4j.

+14

, System.out.println() . , Java I/O.

+15

System.out . , , java.util.logging . ( .)

, . , System.out . , , , , , .

( , System.out.)

+2

, . API Java (java.util.logging). System.out.println - " ", API JDK...

+1

log4j stdout. .

0

System.out . , BufferedOutputStream.

, , , . , StringBuilder.

0

yu

System.setOut( PrintStream ( "all-my-sysouts-go-in-this-file.txt" );

sysoyts...

yu baretail...

, .

.

0

API Java

0

, System.out.print() System.out.println(), , System.out.println() , . - System.out.println() . . BufferedOutputStream BufferedWriter.

, System.out . System.out ; C/++ stdout. , , . , , , System.out, --output.txt.

, , System.out. , , System.err.print() System.err.println().

There is no portable way to get a channel to the "real" console in Java versions prior to 1.6. In 1.6, there is an object class specifically for representing the console: java.io.Console. A reference to this unique object can be obtained from the System class using the static console () method.

But if your requirement is to debug the entire application, while everyone says that using loggers is the best approach.

0
source

All Articles