Java IO Tutorial - Java Console.writer()


Console.writer() has the following syntax.

public PrintWriter writer()


In the following code shows how to use Console.writer() method.

/* w w  w  .  j a va 2 s  .  co m*/
public class Main {
  public static void main(String[] args) throws Exception {

    // creates a console object
    Console cnsl = System.console();

    // if console is not null
    if (cnsl != null) {

      // creates new print writer
      PrintWriter out = cnsl.writer();

      // prints
      out.println("Here is The Optimus Prime!!");


The code above generates the following result.