Java IO Tutorial - Java PrintStream(File file) Constructor








Syntax

PrintStream(File file) constructor from PrintStream has the following syntax.

public PrintStream(File file)   throws FileNotFoundException

Example

In the following code shows how to use PrintStream.PrintStream(File file) constructor.

// w w  w . ja v a 2  s  .  c  o m
import java.io.File;
import java.io.PrintStream;

public class Main {

   public static void main(String[] args) throws Exception {
      byte c = 70;
      PrintStream ps = new PrintStream(new File("c:/text.txt"));

      // write byte c which is character F in ASCII
      ps.write(c);

      // flush the stream
      ps.flush();

   }
}