How Create File Java
In this java program you will see how to create file. To create new empty file instantiate File class with path name and call createNewFile() to create file as below:
package com.javahonk; import java.io.File; public class CreateFile { public static void main(String[] args) { try { File file = new File("C:\\JavaHonk\\File\\JavaHonk.txt"); boolean fileCreated = file.createNewFile(); if (fileCreated) { System.out.println("File created: "+file.getAbsolutePath()); } else { System.out.println("File exists."); } } catch (Exception ex) { ex.printStackTrace(); } } }
- Output:
For more information on File please refer oracle documentation here