Create new empty file - Java File Path IO

Java examples for File Path IO:File Operation

Description

Create new empty file

Demo Code


import java.io.*;
 
public class Main {
 
  public static void main(String[] args) {
     File file = new File("C://demo.txt");
     boolean blnCreated = false;
     try//  w w  w  . j ava 2 s.c o m
     {
       blnCreated = file.createNewFile();
     }
     catch(IOException ioe)
     {
       System.out.println("Error while creating a new empty file :" + ioe);
     }
   
     System.out.println("Was file " + file.getPath() + " created ? : " + blnCreated);
  }
}

Result


Related Tutorials