Created
August 20, 2013 04:03
-
-
Save binjoo/6276993 to your computer and use it in GitHub Desktop.
JAVA:修改百度音乐下载下来的文件名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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