[英]JavaFX external directory and resources outside of jar file
我完成此操作的方式如下:
//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的幻燈片圖像和視頻。 祝您一切順利!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.