我正在尝试使用 将一些 MP3 文件移动到不同的文件夹File.renameTo()
,但是它一直无法正常工作,我不知道为什么。
你能告诉我我做错了什么吗?
File songsFolder = new File("songs");
File[] songsList = songsFolder.listFiles();
for (int i = 0; i < allSongs.size(); i++) {
//allSongs is an ArrayList defined earlier
File music = (File) songsList[i];
FileInputStream fileMusic = new FileInputStream(music);
int size = (int) music.length();
fileMusic.skip(size - 128);
byte[] last128 = new byte[128];
fileMusic.read(last128);
String id3 = new String(last128);
String tag = id3.substring(0, 3);
if (musicsList[i].isFile()) {
File afile = songsList[i];
if (afile.renameTo(new File("songs/" + id3.substring(33, 62).trim() + "/" + songsList[i].getName()))) {
System.out.println("File moved successfully!");
} else {
System.out.println("File failed to move!");
}
}
}
输出是:
File failed to move!
File failed to move!
File failed to move!
File failed to move!