繁体   English   中英

JAR文件外部的JavaFX外部目录和资源

[英]JavaFX external directory and resources outside of jar file

我是Java新手,正在使用JavaFX开发桌面应用程序。 我在项目中创建了一个文件夹,并在其中放置了一些图像。 在客户端上部署后,用户可以替换目录中的映像。 到目前为止,我已经尝试过了,但是还找不到一种方法。 我创建的目录全部都包含在Jar File中。 源码结构:

在此处输入图片说明

编译的Jar:

在此处输入图片说明

使用存档管理器打开Jar文件:

在此处输入图片说明

我需要将“ dic_images”目录放置在jar之外,并能够从代码进行访问,以便用户可以替换其中的图像。 我正在使用NetBeans IDE。

我完成此操作的方式如下:

    //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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM