How do I create a directories recursively?

The code below use File.mkdirs() method to create a collection of directories recursively. It will create a directory with all its necessary parent directories.

package org.kodejava.example.util;


public class CreateDirs {
    public static void main(String[] args) {
        // Define a deep directory structures. Next we wanted to create all the
        // directories.
        String directories = "D:\a\b\c\d\e\f\g\h\i";
        File file = new File(directories);

        // The mkdirs will create folder including any necessary but non existence
        // parent directories. This method returns true if and only if the directory
        // was created along with all necessary parent directories.
        boolean result = file.mkdirs();
        System.out.println("Status = " + result);

How do I rename a file or directory?



public class FileRenameExample {
    public static void main(String[] args) throws IOException {
        // Creates a new file called OldHouses.csv
        File oldFile = new File("OldHouses.csv");

        // Creates the target file.
        File newFile = new File("NewHouses.csv");

        // The renameTo() method renames file or directory to a
        // new name by passing the new destination file.