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



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! ");
          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 .

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment