package com.ld.demo;import java.io.File;/** * 批量修改文件名 * 针对菜鸟要飞下载文件 * @author archer * */public class FileTest { public static final String FLAG = "(更多视频教程关注微信公众号【菜鸟要飞】"; /** * 批量修改文件名 * @param file */ public static void doRename(File file){ try { if(file.exists()){ File[] files = file.listFiles(); if(null != files && files.length>0){ for (int i = 0; i < files.length; i++) { File entity = files[i]; String path = entity.getPath(); String prename = entity.getName(); if(prename.indexOf(FLAG)>=0){ entity.renameTo(new File(path.replaceAll(FLAG, ""))); } doRename(entity); //递归调用 } } } } catch (Exception e) { e.printStackTrace(); } } /** * main * @param args */ public static void main(String[] args) { File file1 = new File("F:/downloads"); doRename(file1); }}