2017-02-21 135 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

嗯,我很高興你發現它有幫助!如果這解決了您的問題,請通過單擊問題的複選標記將其標記爲答案。 –