参考资料:
http://blog.csdn.net/zjml2412/article/details/7916827
import java.io.File;
/**
* 实现将网上下载的文件名统一改名,改为自己想要的名字
*
* [有声下吧www.ysx8.com]04.mp3 ---> 让青春继续第一季04.mp3
*
* [有声下吧www.ysx8.com]05.mp3 ---> 让青春继续第一季05.mp3
*/
public class RenameFile {
public static void main(String args[]) {
String filePath = "E:\\迅雷下载\\让青春继续第一季(全32集)";
// 文件对象作成
File f = new File(filePath);
// 文件是否存在
if (f.exists()) {
// 该文件是否为目录
if (f.isDirectory()) {
// 取得该文件夹下所有的文件
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
// 原文件名取得
String oldName = files[i].getName();
// 新文件名作成
String newHead = "让青春继续第一季";
String newBody = oldName.substring(oldName.length() - 6,
oldName.length());
String newName = newHead + newBody;
// 原文件名和新文件名是否相等
if (!oldName.equals(newName)) {
// 取得该文件父目录
String path = files[i].getParent();
// 新文件对象作成
File newFile = new File(path + "/" + newName);
if (newFile.exists()) {
System.out.println(newName + "已经存在!");
} else {
// 文件重命名
files[i].renameTo(newFile);
System.out.println("(" + oldName + ")" + "--->"
+ "(" + newName + ")" + "重命名成功");
}
}
}
}
} else {
System.out.println("File does not exist!");
}
}
}