public boolean deletefile(String path){ boolean flag = false; File file = new File(path); if (!file.exists()) { return false; } if (!file.isDirectory()) { return false; } String[] str = file.list(); for (int i = 0; i < str.length; i++) { System.out.println("333:"+str[i]); File fi = new File(path + "/" + str[i]); if (path.endsWith(file.separator)) { fi = new File(path + str[i]); } else { fi = new File(path + fi.separator + str[i]); } if(fi.exists()||fi.list().length==0){ File myFilePath = new File(path+"/"+str[i]); myFilePath.delete(); } if(fi.isDirectory())//如果文件假内还有 就继续调用本方法 { deletefile(path+"/"+str[i]); }else{ fi.delete(); } } return true; }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/10256.html