xiaoxiangyu的gravatar头像
xiaoxiangyu 2014-08-29 00:04:37

Java文件操作实现批量修改文件名工具类源代码下载

package org.wuhan.baby.utils.io;
import java.io.File;
public class ReNameFile {
 public static String path = "D:\\abc\\";

 public static void main(String[] args) {
  reName(path);
 }

 public static void reName(String filePath) {
  File rootFile = new File(filePath);
  if (rootFile.isDirectory()) {
   File files[] = rootFile.listFiles();
   if (files != null && files.length > 0) {
    for (int i = 0; i < files.length; i++) {
     File f = files[i];
     if (f.isDirectory()) {
      reName(f.getAbsolutePath());
     } else {
      f.renameTo(new File(path+Math.round(Math.random()*8999+1000)+".jpg"));// 记得将路径也输入
     }
    }
   }
  } else {
   rootFile.renameTo(new File(path+Math.round(Math.random()*8999+1000)+".jpg"));// 记得将路径也输入
  }
 }
}

打赏

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友