Java PrintWriter create from File object

Description

Java PrintWriter create from File object

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) throws IOException {
    File file = new File("Main.java");
    PrintWriter outputFile = new PrintWriter(file);
    outputFile.println("demo2s.com");
    outputFile.close();//w  w w  .ja v  a 2 s  .c o m
    System.out.println("Data written to the file.");

  }
}



PreviousNext

Related