import java.io.*;
public class test {
public
void reName(String path, String from, String to) {
File
f = new File(path);
File[]
fs = f.listFiles();
for
(int i = 0; i < fs.length; ++i) {
File
f2 = fs[i];
if
(f2.isDirectory()) {
reName(f2.getPath(),
from, to);
}
else {
String
name = f2.getName();
if
(name.endsWith(from)) {
f2.renameTo(new
File(f2.getParent() + "/" + name.substring(0, name.indexOf(from)) + to));
}
}
}
}
public
static void main(String[] args) {
test
rf = new test();
rf.reName("d:/11",
".jpg",".jpeg");
}
}
public class test {
}
本文介绍了一个简单的Java程序,该程序能够批量地将指定目录下的文件进行重命名操作。具体而言,用户可以指定文件的旧扩展名和新扩展名,程序会遍历指定路径下所有的子目录,并将符合旧扩展名的文件更改为新扩展名。
4238

被折叠的 条评论
为什么被折叠?



