Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Java Create Directory

 
 

Share on Google+Share on Google+

Java Create Directory

Advertisement
The following example will show how to Create Directory in Java. Though this can be created by using mkdir() also, the following program has used file object in File class.

The following example will show how to Create Directory in Java. Though this can be created by using mkdir() also, the following program has used file object in File class.

'try' and 'catch' are used for exception during execution of the program.

For this we cerate a file object in File class which will create a new directory "Roseindia" in C drive of your computer. If the directory already exists the dierctory won't be created and an output "Directory is already created" will be displayed.

Example of Java Create Directory:

import java.io.File;
import java.io.IOException;

public class CreateFileLocation {
	public static void main(String[] t) {
		File file = new File("c:/Roseindia");
		try {
			if (file.createNewFile()) {
				System.out.println("Directory is created");
			} else {
				System.out.println("Directory is already created");
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}

	}
}
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: May 8, 2013

Related Tutorials

Discuss: Java Create Directory  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com