Friday 11 November 2016

Java Tutorial : Java IO (Java File - How to create a file)


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=Atxf3c64gPM&list=UUhwKlOVR041tngjerWxVccw

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

/*
 *  Create a new file.
 */
public class FileDemo
{

    public static void main(String[] args) throws IOException
    {
        File file = new File("D:/work/myfile.txt");

        /*
         * Atomically creates a new, empty file named by
         * this abstract pathname if and only if a file with
         * this name does not yet exist.
         * 
         * Returns: true if the named file does not exist
         * and was successfully created; false if the named
         * file already exists
         */
        if (file.createNewFile())
        {
            System.out.println("File is created!");
        }
        else
        {
            System.out.println("File already exists.");
        }
    }

}
Output
File is created!

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_File_create_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_File_create_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/882ffbbbc9c8fbb765fb4869059bc3ee253ad31b/BasicJava/JavaIODemo_File_create_App/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment