File Creation In Java Example
Chapter:
File
Last Updated:
15-07-2016 14:18:44 UTC
Program:
/* ............... START ............... */
import java.io.File;
import java.io.IOException;
public class JavaFileCreation {
public static void main(String[] args) {
try {
File file = new File("C:/JavaFile.txt");
if (file.createNewFile())
System.out.println("File has been created");
else
System.out.println("File already exists.");
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
/* ............... END ............... */
Output
Creates a File in C:/JavaFile.txt
Notes:
-
java.io.File.createNewFile() method atomically creates a new file named by this abstract path name.
- Syntax : public boolean createNewFile().
Tags
File Creation, Java