Delete Files with same Prefix String using Java

前端 未结 11 1740
梦谈多话
梦谈多话 2020-12-16 09:11

I have around 500 text files inside a directory with a same prefix in their filename say dailyReport_.

The latter part of the file is the date of the fi

11条回答
  •  生来不讨喜
    2020-12-16 10:12

    Java 8 :

    final File downloadDirectory = new File("directoryPath");   
        final File[] files = downloadDirectory.listFiles( (dir,name) -> name.matches("dailyReport_.*?" ));
        Arrays.asList(files).stream().forEach(File::delete)
    

提交回复
热议问题