Monday, March 2, 2015

JAVA CODE TO DELTE DIRECTORY AND ITS SUB DIRECTORY AND FILES

private static void deleteFile(File file) {
try {
if(file==null){
return;
}
if(file.exists()) {
if(file.isDirectory()){
File[] childFiles = file.listFiles();
if(childFiles!=null && childFiles.length>0){
for (File childFile : childFiles) {
deleteFile(childFile);
}

}
file.delete();
}else{
file.delete();
}
}
}catch(NullPointerException e) {
System.out.println("Problem while Deleting folder, reason : " + e.getMessage());
}catch(SecurityException e) {
System.out.println("Problem while Deleting folder, reason : " + e.getMessage());
}catch(Exception e){
System.out.println("Problem while Deleting folder, reason : " + e.getMessage());
}
}

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...