How to create directories recursively in java

This example shows you how to create directories recursively in java

You can create directories recursively using the File.mkdirs() method, this method create the directory with all its parent directories.

Below id the example of creating directories recursively in java

package com.java.connect.io;

import java.io.File;

//How to create a directories recursively in java
public class RecursivelyDirectoriesExample {
	public static void main(String[] args) {
		// You can define a deep directory structures.
		// We will create all the directories at once
		String folders = "E:\\WORK\\projects\\java-connect-example\\x\\y\\z";
		File file = new File(folders);

		// The mkdirs will create folder including any necessary but
		// nonexistence parent directories.
		// This method returns true if and only if the directory
		// was created along with all necessary parent directories.
		file.mkdirs();
	}
}