a- package demo.io;
- import java.io.File;
- public class DeleteFileDemo {
- /**
- * 删除所有java文件 Java review - 副本
- */
- public static void main(String[] args) {
- File src = new File("c:\\Java review - 副本");
- String suffix = "txt";
- delete(src, suffix);
- }
- private static void delete(File src, String suffix) {
- File[] files = src.listFiles();
- for (File f : files) {
- if (f.isDirectory()) {
- delete(f, suffix);
- } else {
- if (true){//f.getName().endsWith(suffix)) {
- System.out.println(f.getPath()+" deleted..");
- f.delete();
- }
- }
- }
- System.out.println(src.getPath()+" deleted..");
- src.delete();
- }
- }
复制代码
|
|