Sample Programs

Sample java program to created new file

 package org.jusfortechies.example; 

 import java.io.File;
 import java.io.IOException;
 
 public class CreateFile {

   public static void main(String[] args) {
     
     try {
       File file = new File("C:\\samplefile.txt");

       // Create file if it does not exist
       boolean success = file.createNewFile();

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

     } catch (IOException e) {
       System.err.println("File could not be created : " + e);
     }
	
   }

 }




blog comments powered by Disqus