How do I create a new directory?

Bookmark this example!  
Category: java.io, viewed: 1656 time(s).
 
package org.kodejava.sample.java.io;
 
import java.io.File;
 
public class CreateDirectoryExample
{
    public static void main(String[] args)
    {
        // Create an abstract directory
        File file = new File("kodejava");
 
        // 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:\Data\Projects\2005\kodejava-samples\kodejava.
Can't find what you are looking for? Join our FORUMS and ask some questions!

Most Viewed Examples

Latest Code Examples

100 Top & Latest


Locations of visitors to this page
eXTReMe Tracker
visitor stats
Get Chitika Premium