Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe for all free courses

How to create a file in Java ?

Program to demonstrate how to create a file in Java.




Click here to download complete source code 


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

public class CreateFile {

 public static void main(String[] args) {
  
  File file = new File("test.txt");
  
  try {
  
  if(file.createNewFile()) { 
   System.out.println("File successfully created.");
  } else {
   System.out.println("File already exists.");
  }
  
  } catch(IOException ioe) { 
   System.out.println("IO Exception occured.");
  }

 }

}




Click here to download complete source code 


 
© 2021 Learn Java by Examples Template by Hubberspot