How to create a folder in Java

To create a folder in Java you can use on of these 2 Methods

Sample Java

boolean done = (new File("directoryName")).mkdir();  // all ancestor directories must exist!
if (!done) {  
    // failed ()  
}  

Sample Java

boolean done = (new File("directoryName")).mkdirs(); // all directories will be created   
if (!done) {  
    // failed  
}  

Please Share us:
Please rate this snippet

One thought on “How to create a folder in Java

Leave a Reply