How to create a text file in java

The method File.createNewFile() is used to create a new file in Java, and it returns a Boolean value: true if the file is created successfully, otherwise false if the file already exists or the operation failed.

import java.io.File; 
import java.io.IOException;

public class CreateFile
{
public static void main( String[] args )
{
try {

File file = new File("c:\\nouveau_fichier.txt");

if (file.createNewFile()){
System.out.println("File created!");
}else{
System.out.println("File already exists.");
}

} catch (IOException e) {
e.printStackTrace();
}
}
}
Resources:
http://docs.oracle.com/javase/6/docs/api/java/io/File.html#createNewFile()