How do I create a new directory?
Category: java.io, viewed: 4130 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.