Java PrintStream create from File object

Description

Java PrintStream create from File object

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class Main {
  public static void main(String[] args) throws Exception {
    File outFile = new File("Main.txt");
    System.out.println(outFile.getAbsolutePath());
    PrintStream ps = new PrintStream(new FileOutputStream(outFile));

    ps.println("Hello world!");
    ps.println("demo2s.com");
    ps.close();// w w w .j  av a 2 s . c  o m
  }
}



PreviousNext

Related