2017-02-21 138 views
0

我是Java的新手,并使用JavaFX开发桌面应用程序。我在项目中创建了一个文件夹,并在其中放置了一些图像。在客户端上部署后,用户可以替换目录中的图像。到目前为止,我尝试了,我找不到一种方法来做到这一点。我创建的目录全部编译到Jar File中。 源结构:JavaFX外部目录和jar文件以外的资源

enter image description here

编译罐:

enter image description here

打开与归档管理器的Jar文件:

enter image description here

我需要把“ dic_images“目录以外的jar a nd能够从代码访问,以便用户可以替换内部的图像。我正在使用NetBeans IDE。

回答

1

我已经做到了这一点的方法是,像这样:

//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将它用于幻灯片图像和视频。所以你的努力祝你好运!

+0

是的。这是一种可能的解决方法。 :D –

+0

嗯,我很高兴你发现它有帮助!如果这解决了您的问题,请通过单击问题的复选标记将其标记为答案。 –