Sunday, July 10, 2011

File Creation

try {

File f1 = new File("filename");

boolean created = file.createNewFile();

if (created) {

System.out.println("File created.");

} else {

System.out.println("File already exists.");

}

} catch (IOException e) {

}

Since the createNewFile() throws exception we have to either throw it while declaring the class or put the file creation code in ‘try’ block and catch the exception.

No comments:

Post a Comment