1 import java.io.File;
2
3 //批量更改文件夹内的文件名
4 public class replaceFileName {
5 public static void main(String[] args) {
6 String fileName="Z:\\Users\\caixl\\Desktop\\0207";
7 File f=new File(fileName);
8 print(f);
9 }
10 public static void print(File f){
11 if(f!=null){
12 if(f.isDirectory()){
13 File[] fileArray=f.listFiles();
14 if(fileArray!=null){
15 for (int i = 0; i < fileArray.length; i++) {
16 //递归调用
17 print(fileArray[i]);
18 }
19 }
20 }
21 else{
22 String filename = f.getName();
23 String path = f.getParent();
24 //文件名的2208更改为0207
25 String newFileName = filename.replace("2208", "0207");
26 f.renameTo(new File(path+"\\"+newFileName));
27 }
28 }
29 }
30 }