Tutorials4u.net Forum
Java code to create directory with example also to check the directory exist - Printable Version

+- Tutorials4u.net Forum (http://www.tutorials4u.net/forum)
+-- Forum: Discussion Forum (/forumdisplay.php?fid=1)
+--- Forum: JAVA (/forumdisplay.php?fid=2)
+--- Thread: Java code to create directory with example also to check the directory exist (/showthread.php?tid=76)


Java code to create directory with example also to check the directory exist - tutorials4u - 02-06-2011 08:46 AM

Java code to create directory with example also to check the directory exist using Java IO API

Find below the example code

import java.io.File;

public class TestCode {

public static void main(String[] args) throws Exception {
File dest = new File("C:/Global/Test/Sample");
if (!folderExist(dest)) {
createFolder(dest);
}

}

public static boolean createFolder(File filename) {
System.out.println("createFolder:Start");
boolean makedir = filename.mkdirs();
System.out.println("createFolder:End");
return makedir;
}

public static boolean folderExist(File filename) {
//String parent = filename.getParent();
System.out.println("folderExist:Start");
if (!filename.exists()) {
System.out.println("folderExist:End");
return false;

} else {
System.out.println("folderExist:End");
return true;
}
}
}