为什么我不能移动 .mp3 文件,而是 .txts?
Why can't I move .mp3-files, but .txts?
所以我目前正在尝试通过 Java 移动 .mp3 文件。之后他们应该被放置在他们的解释和专辑的文件夹中
我想出了这个代码:
import java.io.File;
public class Storage {
String location;
public Storage(String location){
this.location = location;
}
public void createFolderIfNotExisting(String name){
File folder = new File(location+name);
if(!folder.exists()){
folder.mkdir();
}
}
public void putInto(String file, String interpret, String album){
createFolderIfNotExisting(interpret);
createFolderIfNotExisting(interpret + "//" + album);
File currentFile = new File(location + file);
File futureFile = new File(location + interpret + "//" + album + "//" + file);
currentFile.renameTo(futureFile);
}
}
(位置必须在 //
结束)(编辑)
(位置必须在 /
结束)
它似乎正在创建文件夹。但它并没有移动 mp3 文件。如果我尝试对 .txt 文件进行同样的操作,.txt 文件会被移动,这对我来说很奇怪。
我还检查了 .mp3 文件是否被正确识别。因此我使用了 currentFile.exists()
。确实如此。
所以...我真的迷路了。帮助将不胜感激。 :)
感谢 Kayman,他帮助我找出了语法错误。
代码本身完全没问题。 :)
所以我目前正在尝试通过 Java 移动 .mp3 文件。之后他们应该被放置在他们的解释和专辑的文件夹中
我想出了这个代码:
import java.io.File;
public class Storage {
String location;
public Storage(String location){
this.location = location;
}
public void createFolderIfNotExisting(String name){
File folder = new File(location+name);
if(!folder.exists()){
folder.mkdir();
}
}
public void putInto(String file, String interpret, String album){
createFolderIfNotExisting(interpret);
createFolderIfNotExisting(interpret + "//" + album);
File currentFile = new File(location + file);
File futureFile = new File(location + interpret + "//" + album + "//" + file);
currentFile.renameTo(futureFile);
}
}
(位置必须在 (编辑)
(位置必须在 //
结束)/
结束)
它似乎正在创建文件夹。但它并没有移动 mp3 文件。如果我尝试对 .txt 文件进行同样的操作,.txt 文件会被移动,这对我来说很奇怪。
我还检查了 .mp3 文件是否被正确识别。因此我使用了 currentFile.exists()
。确实如此。
所以...我真的迷路了。帮助将不胜感激。 :)
感谢 Kayman,他帮助我找出了语法错误。
代码本身完全没问题。 :)