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());
}
}
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