Showing posts from October 14, 2011

Creation and Deletion of folders in Java

Think the program is self-explanatory. Please write to me if I have missed anything or if you have any more doubts.

 * @author shankar
//This Program will illustrate how to create and delete folders using Java code
public class JavaApplication1 {

    public static void main(String[] args) {
            //Mention the folder to be created in the constructor
            //The entire file structure will be created
            File folder = new File("G:/tempfolder/temp1");
            folder.mkdirs(); //this will create the entire File structure if it does not exists

            File folder1= new File("G:/tempfolder/temp1/temp2"); 
            folder1.mkdir(); //this will create the last folder alone if the corresponding path exists

            boolean value = folder1.delete(); // this will delete the temp2 folder alone
                System.out.println("File Deleted");