Tuesday, May 10, 2011

Create a File

For this createNewFile() method is used. It returns true if file is created and false otherwise. So for eg. it returns false if file already exist, so it can't create the new file here.

import java.io.*;
//now wherever you want do this:
public static void main(String[] args){
File file = new File("C://demo.txt");
boolean isCreated;
isCreated= file.createNewFile();
catch(IOException ioe)
System.out.println("Error in creating a new empty file :" + ioe);

No comments:

Post a Comment