Java file new directory


 

Java file new directory

In this section, you will learn how to create a new directory.

In this section, you will learn how to create a new directory.

Java file new directory

In this section, you will learn how to create a new directory.

Description of code:

This is a common task. The java.io.package provides various useful tools that has made the file handling easier. Programming has now became much easier.

You can see in the given example, we have created an object of File class and specify a directory which you want to create. Then we have called the method mkdir() through the object of file class. On executing the given code, you will get the newly generated directory in the given path.

Here is the code:

import java.io.*;

public class FileNewDirectory {
	public static void main(String args[]) {
		File file = new File("Hello");
		file.mkdir();
	}
}

By using the method mkdir(), you can create a directory in the given path.

Ads