Preview .7z content and subfolders without extracting

I would like to view .7z content without extracting it using Java, so I tried using Apache Commons Compress:

public static void main(String[] args) {
    try {
        SevenZFile sevenZFile = new SevenZFile(new File("C://test.7z"));
        SevenZArchiveEntry entry;
        while ((entry = sevenZFile.getNextEntry()) != null) {
            System.out.println("Name: " + entry.getName());
            System.out.println("Size : " + entry.getSize());
            System.out.println("--------------------------------");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

It works, but I would also like to view files in another 7z or zip from the original 7z:

test.7z
--- file1.txt
--- otherInner.7z
    ---- innerFile1.txt
    ---- innerFile2.txt

Does it make sense to do this without extracting 7z? Thank you for your help.

+4
source share
1 answer

View. Do you mean without extracting the external 7z? Yes. without extracting internal 7z? No.

It seems that Apache Commons SevenZ only works with file objects, so you need to at least extract the internal 7z file, then decode it.

entry, , . (temp), SevenZFile .

Apache Common Compress Examples:

SevenZFile sevenZFile =...
SevenZArchiveEntry entry...

...found our entry we want...
byte[] content = new byte[entry.getSize()];
LOOP UNTIL entry.getSize() HAS BEEN READ {
    sevenZFile.read(content, offset, content.length - offset);
}

, , byte[], , SeventZFile.

, [] temp, - .

+1

Source: https://habr.com/ru/post/1612442/


All Articles