java examples
Home Java Examples Resources Java Interview Questions
Brainpower SEO

How to create a new directory?



public class CreateDirectoryExample
    public static void main(String[] args)
        // Create an abstract directory
        File file = new File("javacoderanch");

        // Create the directory by calling mkdir() method. This
        // method return true if and only if the directory was
        // created. If false is returnned no directory is created
        // because for instance the directory was already exists.
        if (file.mkdir())
            System.out.println("Directory = " + file.getAbsolutePath() + ".");
        } else
            System.out.println("No directory was created.");

Here is the result of the program:

Directory = D:DataProjects2005javacoderanch-samplesjavacoderanch.