使用Java中File类批量创建文件和批量修改文件名

批量创建文件

1         int cont = 1;
2         String s = "E:\学习资料\Java笔记-";
3         while(cont<100){
4             File f = new File(s+cont+".txt");
5             if(!f.exists()){
6                 f.createNewFile();
7             }
8             cont++;
9         }

批量修改文件名

 1         File file = new File("E:\学习资料");
 2         String sf = file.getAbsolutePath();
 3         File[] f= file.listFiles();
 4         int cont =1;
 5         for (File file2 : f) {
 6             String oldname = file2.getName();
 7             String name = oldname.replace("Java笔记-", "");
 8             String newname = sf+"\"+name;
 9             File ff = new File(newname);
10             boolean b =file2.renameTo(ff);
11             
12             if(b){
13                 System.out.println("修改成功"+cont+"个文件");
14                 cont++;
15             }
16         }
原文地址:https://www.cnblogs.com/jpwz/p/5695984.html