简体   繁体   English

Java Apache Commons Compress 7zip,损坏的文件错误

[英]Java Apache Commons Compress 7zip, corrupt file error

7 zip files (lzma) format, want to compress and encrypt. 7个zip文件(lzma)格式,要压缩和加密。
I want to use Apache Commons Compress. 我想使用Apache Commons Compress。
I am using this function, however, the decompressed files are corrupted. 我正在使用此功能,但是,解压缩的文件已损坏。

Thanks 谢谢

public static void main(String args[]) throws FileNotFoundException, IOException {
    SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("outFile.7z"));
    File entryFile = new File("D:/image.jpg");
    SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(entryFile, entryFile.getName());

    byte fileContent[] = new byte[(int)entryFile.length()];

    sevenZOutput.putArchiveEntry(entry);
    sevenZOutput.write(fileContent);
    sevenZOutput.closeArchiveEntry();
    sevenZOutput.close();         
}

I figured, okay, thank you. 我想,好的,谢谢。 How do I encryption the archive? 如何加密存档?

public static void main(String args[]) throws FileNotFoundException, IOException {
SevenZOutputFile sevenZOutput = new SevenZOutputFile(new File("outFile.7z"));
File entryFile = new File("D:/image.jpg");
SevenZArchiveEntry entry = sevenZOutput.createArchiveEntry(entryFile, entryFile.getName());
sevenZOutput.putArchiveEntry(entry);

FileInputStream in = new FileInputStream(entryFile);
                int len;
                byte buffer[] = new byte[8192];
                int transferedMegaBytes2=0;
                while ((len = in.read(buffer)) > 0) {
                    sevenZOutput.write(buffer, 0, len);                    
                    transferredBytes += len;
                    int transferedMegaBytes = (int) (transferredBytes / 1048576);                          
                    if(transferedMegaBytes>transferedMegaBytes2){
                    System.out.println("Transferred: " + transferedMegaBytes + " Megabytes.");
                    transferedMegaBytes2=transferedMegaBytes;
                    }
                }
sevenZOutput.closeArchiveEntry();
sevenZOutput.close();    
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java / Apache Commons Compress中zip64文件的ZipFile构造函数变慢 - ZipFile constructor slow for zip64 file in Java/Apache Commons Compress 如何使用Apache Commons Compress创建加密的Zip文件? - How to create a encrypted Zip file with Apache Commons Compress? 使用commons.apache.compress将条目添加到嵌套zip文件中 - Adding an entry to nested zip File using commons.apache.compress 如何使用 apache.compress 创建受密码保护的 zip/7zip 文件 - How to create password protected zip/7zip file using apache.compress 通过Apache POI和Java Web应用程序读取Excel,但显示错误为“ java.io.IOException:org / apache / commons / compress / archivers / zip / ZipFile” - Reading Excel by Apache POI and Java web application but showing error as “java.io.IOException: org/apache/commons/compress/archivers/zip/ZipFile” Apache Commons Compress 作为 Zip Bomb 的解决方案 - Apache Commons Compress as solution to Zip Bomb 使用 apache.commons.compress.archivers.zip 读取远程 zip 文件 - Reading remote zip file using apache.commons.compress.archivers.zip apache POI java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile - apache POI java.lang.NoClassDefFoundError: org/apache/commons/compress/archivers/zip/ZipFile Apache Commons压缩7z文件的大小比p7zip压缩大 - Apache commons compress 7z file size way bigger than p7zip compression 在Java中使用apache commons vfs2访问后删除zip文件 - Deleting zip file after accessing with apache commons vfs2 in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM