Friday, July 15, 2016

Is Possible to print message without using system.out.println?

Is Possible to print message without using system.out.println?

Is possible to print message without using system.out.println?

Yes. It is possible to print message without using system.out.println.

package com.javasunderesan;

import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.PrintStream;
public class PrintMessage {
  public static void main(String[] args) {
    // https://javasunderesan.blogspot.in/
    // Display message without System.out.println
    try {
      String message = "javasunderesan - Learn Java\n";
      System.out.write(message.getBytes());
      System.out.format("%s", message);
      PrintStream myout = new PrintStream(new FileOutputStream(FileDescriptor.out));
      myout.print(message);
      System.err.print(message);
      System.console().writer().println(message);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

No comments :

Post a Comment