Skip to content

Instantly share code, notes, and snippets.

@binjoo
Created August 20, 2013 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binjoo/6276993 to your computer and use it in GitHub Desktop.
Save binjoo/6276993 to your computer and use it in GitHub Desktop.
JAVA:修改百度音乐下载下来的文件名
package net.binjoo;
import java.io.File;
public class UpdateMp3Name {
public static void main(String[] args) {
String oldPath = "E:\\BaiduMusic\\Songs";
File file = new File(oldPath);
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
File oldFile = (File) files[i];
String oldName = oldFile.getName();
String[] names = oldName.split(" - ");
String n1 = names[1].split("[.]")[0];
String n2 = names[0];
String newName = n1 + " - " + n2 + ".mp3";
File newFile = new File(oldFile.getParent() + "\\" + newName);
System.out.print(newFile.getPath());
if (oldFile.renameTo(newFile)) {
System.out.println(" === 修改成功!");
} else {
System.out.println(" === 修改失败!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment