Saturday, January 10, 2015

New File Creation in java pgm



New File Creation

import java.io.File;
import java.io.IOException;
public class Main 
 {
   public static void main(String[] args) 
   {
      try
        {
         File file = new File("C:/myfile.txt");
         if(file.createNewFile())
         System.out.println("Success!");
         else
         System.out.println ("Error, file already exists.");
     }
     catch(IOException ioe) 
    {
        ioe.printStackTrace();
     }
   }
}

No comments:

Post a Comment