1// importing the File class
2import java.io.File;
3
4class Main {
5 public static void main(String[] args) {
6
7 // create a file object for the current location
8 File file = new File("newFile.txt");
9
10 try {
11
12 // trying to create a file based on the object
13 boolean value = file.createNewFile();
14 if (value) {
15 System.out.println("The new file is created.");
16 }
17 else {
18 System.out.println("The file already exists.");
19 }
20 }
21 catch(Exception e) {
22 e.getStackTrace();
23 }
24 }
25}
26