java遞歸刪除文件及目錄
阿新 • • 發佈:2017-07-20
port imp pos let 刪除文件夾 static -a tor list
package base;
import java.io.File;
public class delete {
public static void main(String[] args) {
deleteFileAndFoder("../yang");
}
static void deleteFileAndFoder(String path){
File f=new File(path);
if(f.isDirectory()){//假設是文件夾。先遞歸刪除
String[] list=f.list();
for(int i=0;i<list.length;i++){
deleteFileAndFoder(path+"//"+list[i]);//先刪除文件夾下的文件
}
}
f.delete();
}
}
import java.io.File;
public class delete {
public static void main(String[] args) {
deleteFileAndFoder("../yang");
}
static void deleteFileAndFoder(String path){
File f=new File(path);
if(f.isDirectory()){//假設是文件夾。先遞歸刪除
String[] list=f.list();
for(int i=0;i<list.length;i++){
deleteFileAndFoder(path+"//"+list[i]);//先刪除文件夾下的文件
}
}
f.delete();
}
}
java遞歸刪除文件及目錄