Create a file in Java

The File class has three constructors and a number of useful methods. The following are the three constructors:
File("file name") File("Directory name") File("directory name", "Filename")
How do I create a file  in Java Use File.createNewFile() method to create a file. This method returns a boolean value : true if the file is created successfully in the path specified; false if the file is already exists or the program failed for some reason.
import java.util.*; import java.io.*; class TestClass{ public static void main( String[] args ) { try{ File file = new File("c:\\temp.txt"); if (file.createNewFile()){ //return true System.out.println("New file is created!!"); }else{ //return false System.out.println("temp.txt already exists."); } } catch (IOException e) { e.printStackTrace(); } } }
Output
New file is created!