Skip to content

Commit

Permalink
check list is null and use foreach instead of fori
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzq7 committed Nov 1, 2022
1 parent 625b911 commit 8d30c98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -774,14 +774,14 @@ private static void deleteFile(String dirPath) {
return;
}
File[] fileList = fileDirToDel.listFiles();

for (int i = 0; i < fileList.length; i++) {
File file = fileList[i];
if (file.isFile() && file.exists()) {
boolean delete = file.delete();
} else if (file.isDirectory()) {
deleteFile(file.getAbsolutePath());
file.delete();
if (fileList != null) {
for (File file : fileList) {
if (file.isFile() && file.exists()) {
file.delete();
} else if (file.isDirectory()) {
deleteFile(file.getAbsolutePath());
file.delete();
}
}
}
fileDirToDel.delete();
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/io/mycat/util/dataMigrator/DataMigratorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ public static long countLine(File file) throws IOException{
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
if (children != null) {
for (String child : children) {
boolean success = deleteDir(new File(dir, child));
if (!success) {
return false;
}
}
}
}
// 目录此时为空,可以删除
return dir.delete();
Expand Down

0 comments on commit 8d30c98

Please sign in to comment.