繁体   English   中英

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

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

7个zip文件(lzma)格式,要压缩和加密。
我想使用Apache Commons Compress。
我正在使用此功能,但是,解压缩的文件已损坏。

谢谢

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();         
}

我想,好的,谢谢。 如何加密存档?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM