admin管理员组

文章数量:1516870

解压读写.7z格式的压缩文件,Java

需要先在pom.xml里面添加引用:

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-compress</artifactId>
            <version>1.21</version>
        </dependency>
        <dependency>
            <groupId>org.tukaani</groupId>
            <artifactId>xz</artifactId>
            <version>1.9</version>
        </dependency>

Java代码:

   /**
     * @param file 原始的.7z文件
     * @throws Exception
     */
    private void unzip7Z(File file) throws Exception {
        SevenZFile zFile = new SevenZFile(file);
        SevenZArchiveEntry entry;
        while ((entry = zFile.getNextEntry()) != null) {
            String name = entry.getName();
            System.out.println("文件:" + name);
            InputStream is = zFile.getInputStream(entry);
            BufferedInputStream bis = new BufferedInputStream(is);
            //这里开始,从.7z文件中读取其中一个压缩文件就变成常规的写文件操作
            //...
        }

本文标签: 技巧文件掌握