Post Reply 
 
Thread Rating:
  • 1 Votes - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java code to create directory with example also to check the directory exist
02-06-2011, 08:46 AM
Post: #1
Java code to create directory with example also to check the directory exist
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;
}
}
}
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:



Send your comments, Suggestions or Queries regarding this site at info@tutorials4u.net

Copyright © 2010 Tutorials4u.net All Rights Reserved