PrintStream


PrintStream

This class adds data to other output stream. It has the ability to print representations of various data values conveniently. This class inherits methods from the Java.io.FilterOutputStream and Java.io.Object classes.

Syntax for declaring java.io.PrintStream class:

public class PrintStream extends FilterOutputStream implements Appendable, Closeable

Print Writer

This class prints formatted representations of objects to a text-output stream. It inherits methods from the java.io.Object class .

Syntax for declaring java.io.PrintWriter class:

public class PrintWriter extends Writer

Example:

Com.knowledge2life import java.io.File; import java.io.PrintWriter; class PrintWriterExample { public static void main(String[] args) throws Exception { PrintWriter writer = new PrintWriter(System.out); writer.write("Knowledge2life."); writer.flush(); writer.close(); PrintWriter writer1 =null; writer1 = new PrintWriter(new File("Knowledge2life.txt")); writer1.write("Like Java, Spring, Hibernate, Android, PHP etc."); writer1.flush(); writer1.close(); } }

OUTPUT:

Knowledge2life