Sunday, 11 June 2017

Java Tutorial : Java IO (Java File - How to create the directory) ~ foundjava


Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial : Java IO (Java File - How to create the directory) 
FileDemo1.java
import java.io.File;

public class FileDemo1
{

    public static void main(String[] args)
    {
        File file = new File("D:/work/java");
        /*
         * Creates the directory named by this abstract
         * pathname.
         * 
         * Returns: true if and only if the directory was
         * created; false otherwise
         */
        boolean dirCreated = file.mkdir();
        System.out.println(file.getAbsolutePath()
                + " directory Created? = " + dirCreated);
    }

}
Output
D:\work\java directory Created? = true
FileDemo2.java
import java.io.File;

public class FileDemo2
{

    public static void main(String[] args)
    {
        File file = new File("D:/work/java/arraylist/src");
        /*
         * Creates the directory named by this abstract
         * pathname, including any necessary but nonexistent
         * parent directories.
         *
         * Returns: true if and only if the directory was
         * created, along with all necessary parent
         * directories; false otherwise
         */
        boolean dirCreated = file.mkdirs();
        System.out.println(file.getAbsolutePath()
                + " directory Created ? = " + dirCreated);
    }

}
Output
D:\work\java\arraylist\src directory Created ? = true

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment