0
所以我目前正試圖通過Java移動.mp3文件。隨後,他們應放置在文件夾中爲自己解釋和專輯爲什麼我不能移動.mp3文件,但是.txts?
在那裏,我想出了這個代碼:
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()
。它是。
所以......我真的迷失在這裏。我們將非常感謝幫助。 :)
你爲什麼使用'/ /'?目錄分隔符是'/'(至少就Java而言)。 – Kayaman
這就是我學習它的方式。 (在學校教授。)Windows至少在我看來是用'//'替換它們的。 ''//對我和所有學校項目來說總是很好。 – oRookie
據我所知,你只需要一個雙斜槓反斜槓「\\」Java的工作與一個單一的正斜槓「/」目錄 – Thraydor