批量创建文件

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         }

 

相关文章:

猜你喜欢
  • 2021-11-14
  • 2021-10-19
  • 2021-07-21
  • 2021-10-30
  • 2021-11-23
  • 2022-01-22
  • 2021-12-13
相关资源
相似解决方案