Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Java Create Directory - Java Tutorial

                         

In the section of Java Tutorial you will learn how to create directory using java program. This program also explains the process of creating all non-existent ancestor directories automatically. We will use the class File class to crate the directory.

Class File
The File class an abstract representation of file and directory pathnames. File class is used to interact with the files system.


Here is the code for creating directory and all non-existing ancestor directories:

import java.io.*;
class CreateDirectory 
{
   public static void main(String args[])
  {
      try{
    String strDirectoy =
"test";
    String strManyDirectories="dir1/dir2/dir3";

    // Create one directory
    boolean success = (new File(strDirectoy)).mkdir();
    if (success) {
      System.out.println("Directory: " + strDirectoy + " created");
    }    
  

    // Create multiple directories
    success = (new File(strManyDirectories)).mkdirs();
    if (success) {
      System.out.println("Directories: " + strManyDirectories + " created");
    }

    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}

Download the code

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

8 comments so far (post your own) View All Comments Latest 10 Comments:

I'm a trainee s/w engineer.
I want to create an application in java. After completing the project I want to install it as a complete project i.e. java software .But I don't know how to create exe for installation.

Posted by subodh on Wednesday, 07.30.08 @ 19:18pm | #69999

simple but effective example.. very easy to follow

Posted by srikanth on Monday, 12.3.07 @ 17:44pm | #41185

Thank you very much,a really simple and practice example!

Posted by Manuela on Tuesday, 01.9.07 @ 23:43pm | #3072

Wht can I say abt roseindia.net, It is awesome. Excellent course material for beginners, It made me easy to brush-up JAVA, actually I forgot JAVA since I was very much into other application programming.

Now, I m very much confident abt JAVA, Thank U RoseIndia for ur valuable effort.

Posted by Rajee L on Tuesday, 12.19.06 @ 14:27pm | #1231

thank you very much. It's easy to understand.

Posted by arbujung on Thursday, 12.14.06 @ 10:07am | #1003

Thanks a lot it did help :)

Posted by SLizer3D on Saturday, 12.9.06 @ 13:56pm | #687

Its really useful and very easy to knew the basic concepts with out any illusion.Absolutely great feast to the beginners.

Posted by Balakrishnan.R on Wednesday, 12.6.06 @ 20:31pm | #534

It's really nice.Basic flow depicted here really providing track for the begineers to continue and brings confidence in them to proceed further.Keep it up.

Posted by Balakrishnan.R on Wednesday, 12.6.06 @ 20:06pm | #515

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.