我已经做到了这一点的方法是,像这样:
//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 –
嗯,我很高兴你发现它有帮助!如果这解决了您的问题,请通过单击问题的复选标记将其标记为答案。 –