Showing posts with label Creating Text File in Java. Show all posts
Showing posts with label Creating Text File in Java. Show all posts

Friday, 25 July 2014

How to create a text file in java

Structure of the Problem Requirements 


In this problem we learn how to create a text file in Java. This file will be empty and create if their is no file with that name already exist. If file exist already the error message will be display else program execute successfully with the message your file is created!.

Source Code


package www.ancodingpoint.com;

import java.io.File;

public class Creating_File {

  public static void main(String[] args) {
      try {
          File f = new File (" ancodingpoint.txt ");
          if (f.createNewFile())
              System.out.println(" Your File is Created! ");
          else 
          System.out.print(" File Already Exist  ");
      }
               catch (Exception e)
              {
        System.out.println(" Error found ");
    }
  }
}

Output of the Program  


Java Filing Programming
File Creation in Java







Note : The Text File will be created in the Netbeans Project and within your package .