import java.io.File;
public class TestDelete {
public static void main(String[] args) {
delete(new File("D:\\test"),"1.doc");
}
private static void delete(File file,String fileName){
if(file.isDirectory()){
File[] files = file.listFiles();
for (File temp : files) {
delete(temp,fileName);
}
}else{
String name=file.getName();
if(fileName.equals(name)){
file.delete();
}
}
}
}
转载于:https://blog.51cto.com/wangpeng1206/1196744