Create new empty file with java



User Rating:  / 23
PoorBest 
Details

simple code for create new empty file :

View source
package com.developerpages.snippets.core;
 
import java.io.File;
import java.io.IOException;
 
public class CreateNewEmptyFile {
 
    public static void main(String[] args) {
        File file = new File("C://test.txt");
        boolean fileCreated = false;
        try {
            fileCreated = file.createNewFile();
        } catch (IOException ioe) {
            System.out.println("Error while creating empty file: " + ioe);
        }
 
        if (fileCreated) {
            System.out.println("Created empty file: " + file.getPath());
        } else {
            System.out.println("Failed to create empty file: " + file.getPath());
        }
 
    }
}
 


You have no rights to post comments

   

Login  

   

     

© Developerpages