Share on Google+Share on Google+

Java file new directory

Advertisement
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.

Advertisements

Posted on: May 22, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.