2012-06-07 54 views
0

我的應用程序jar中有一些默認配置文件,如果它們不存在,我想將它們保存到文件系統中。我希望它也保持目錄結構。示例:在Java中獲取ZIP文件中的目錄內容

Jar file 
-configs/ 
    -main-config.cfg 
    -another-file.txt 
    -stuff/ 
     -another-file.cfg 
-com/ 
-META-INF/ 

我想將configs /的內容鏡像到文件系統,包括子文件夾。

+0

可能的重複:http://stackoverflow.com/questions/981578/how-to-unzip-files-recursively-in-java – rlegendi

回答

1

使用JarFile.entries可以獲得Jar文件中所有條目的枚舉。

+0

我將如何檢查他們在我想要的目錄等?我之前幾乎沒有使用過zip/jar包。 –

+0

@SeanGordon您可以獲取條目的[name](http://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipEntry.html#getName()),看看它是否[開始](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#startsWith(java.lang.String))和你想要的目錄。 – Jeffrey