0

zip フォルダー内のファイルを一覧表示しようとしています。zip4j ライブラリまたは JavaZipFileクラスを使用できることを理解しています。

私の質問は、これらのツールのいずれかを使用することです。zip 内の特定のディレクトリにあるファイルを一覧表示するにはどうすればよいですか?

4

1 に答える 1

1

ZipInputStreamだけでタスクを解決することができます。

final String folderNameToBrowse = "folder_name";
final String archivePath = "archive.zip";
final Path pathToBrowse = Paths.get(folderNameToBrowse);        

ZipInputStream zis = new ZipInputStream(new FileInputStream(archivePath));

ZipEntry temp = null;            
while ( (temp = zis.getNextEntry()) != null) {
    if(!temp.isDirectory()){
        Path currentPath = Paths.get(temp.getName());                    
        if(pathToBrowse.equals(currentPath.getParent())){
            // Here is the file name
            System.out.println(currentPath.getFileName());
        }
    }
}
于 2015-10-28T06:08:55.563 に答える