views:

247

answers:

4

What is the most efficient class to use to read from and write to console in Java?

+1  A: 

Like System.{out,in}?

John Paulett
+1  A: 

BufferedReader and BufferedWriter are the most efficient means of writing to and reading from the console, as well as any file. However, they are relatively difficult to use.

Scanner provides an alternative to retrieving input from the command line, and is much easier to use than BufferedReader.

Swiss
+2  A: 

Java 1.6 has a Console class that simplifies some things. In general, System.out and Scanner on top of System.in are usually enough.

tulskiy
+1  A: 

If you are printing log messages in an application, should use a logging API (log4j or whatever). You then specify which levels (debug, info, warn, ...) print on the console per class.

Logging tends to slow things down dramatically in my experience - so don't log within a tight loop (unless that logging level is typically off in production).

LES2