我已經做到了這一點的方法是,像這樣:
//Make a dir using the users home directory and a filename.
File dir = new File(System.getProperty("user.home") + "/NameOfDir/");
//List the files in that dir
File[] listOfFiles = dir.listFiles();
//If there are no files, do stuff.
if (listOfFiles == null) {
//If the dir doesn't exist already, make it.
if (!dir.exists()) {
dir.mkdir();
}
//Do stuff in the empty dir
} else {
//List the file names in the dir
List<String> fileNamesList = new ArrayList<String>(Arrays.asList(dir.list()));
//Do stuff with the files list.
}
這將確保該目錄存在,如果沒有它將使。然後你可以隨時做任何你需要做的事情。
我用JavaFX將它用於幻燈片圖像和視頻。所以你的努力祝你好運!
是的。這是一種可能的解決方法。 :D –
嗯,我很高興你發現它有幫助!如果這解決了您的問題,請通過單擊問題的複選標記將其標記爲答案。 –