To create file in Java we will use the File class and method createNewFile()

Code:

1
2
File myFile = new File("c:\\myFile.txt");
myFile.createNewFile();

And if you do not see exception, our file will be created

This method returns a boolean value: true – if the file has created, false – file already exists