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"));// 记得将路径也输入 } } }
猜你喜欢
请下载代码后再发表评论



139465 LV12
2023年3月29日
好的好的 LV8
2022年7月4日
sswert LV2
2022年3月18日
wyx065747 LV67
2022年3月2日
rescuer023 LV1
2021年7月5日
Savemylife
2021年5月25日
暂无贡献等级
不抓老鼠 LV7
2021年1月12日
zhyp29 LV3
2020年12月18日
dongzhan LV12
2020年12月7日
hahaenenene LV8
2020年9月2日