7Z 아카이브와 협력합니다

개요

7-zip은 압축 비율이 높은 파일 아카이버입니다. aspose.zip api를 사용하면 다른 제 3 자 애플리케이션없이 응용 프로그램에서 7 개의 zip 아카이브를 작성하고 관리하는 작업을 수행 할 수 있습니다. aspose.zip api는 7-zip 아카이브와 함께 작동하기 위해 Sevenziparchive 클래스를 제공합니다. 이 클래스는 아카이브에서 작업을 수행하는 다양한 방법을 제공합니다. API는 7Z 아카이브 내에서 단일 파일을 나타 내기 위해 SevenziparchiveEntry 클래스를 제공합니다.

7- zip 단일 항목 만들기

다음 코드 예제는 Sevenziparchive 인스턴스를 사용하여 7-zip 항목을 만드는 방법을 보여줍니다.

1try (fileoutputStream SevenzipFile = new FileOutputStream ( "Archive.7Z")) {
2    try (sevenziparchive archive = new sevenziparchive ()) {
3        archive.createentry ( "data.bin", "file.dat");
4        Archive.save (Sevenzipfile);
5    }
6} catch (ioException ex) {
7}

7 zip 아카이브 항목 만들기

Sevenziparchive 클래스는 주어진 디렉토리에 파일과 디렉토리를 재귀 적으로 추가하는 CreateEntries 메소드를 제공합니다. 다음 코드 예제는 7-zip 아카이브 항목을 만드는 방법을 보여줍니다.

1try (sevenziparchive archive = new sevenziparchive ()) {
2    Archive.createentries ( "Datadir");
3    Archive.save ( "Sevenzip.7Z");
4}

7-zip 암호화 설정

aspose.zip api는 7zipaesencryptionsettings 7Z 아카이브에 대한 AES 암호화 또는 암호 해독에 대한 설정을 제공하는 클래스를 제공합니다. 다음 코드 예제는 AES 암호화 설정을 제공하는 방법을 보여줍니다.

1try (sevenziparchive archive = new sevenziparchive (new sevenzipentrysettings (null, new sevenzipaesencryptionsetstings ( "p@s $")))) {
2    Archive.CreateEntry ( "data.bin", New BytearrayInputStream (new Byte [] {0x00, (byte) 0xff}));
3    Archive.save ( "Archive.7Z");
4}

AES-256은 7Z 아카이브의 유일한 암호화 방법입니다.

LZMA 압축을 가진 7- Zip 아카이브

다음 코드 예제는 LZMA 압축 및 AES 암호화로 7Z 아카이브를 만드는 방법을 보여줍니다.

 1try (fileoutputStream SevenzipFile = new FileOutputStream ( "Archive.7Z")) {
 2    try (sevenziparchive archive = new sevenziparchive ()) {
 3        archive.createentry ( "enterg1.bin",
 4                New BytearRayInputStream (New Byte [] {0x00, (byte) 0xff}),
 5                New SevenzipentRySettings (New SevenziplzmacompressionSettings (),
 6                        New Sevenzipaesencryptionsettings ( "test1")),
 7                 파일 ( "data1.bin"));
 8        Archive.save (Sevenzipfile);
 9    }
10} catch (ioException ex) {
11}

마찬가지로 BZIP2, PPMD ​​및 LZMA2 압축 방법으로 7Z 아카이브를 구성하거나 압축없이 파일을 저장할 수 있습니다.

항목에 대한 다른 비밀번호 설정

다음 코드 예제는 각 항목마다 다른 암호로 암호화 된 항목으로 아카이브를 만드는 방법을 보여줍니다.

 1try (fileoutputStream SevenzipFile = new FileOutputStream ( "Archive.7Z")) {
 2    파일 fi1 =  파일 ( "data1.bin");
 3    파일 fi2 =  파일 ( "data2.bin");
 4    파일 fi3 =  파일 ( "data3.bin");
 5
 6    try (SevenZipArchive archive = new SevenZipArchive()) {
 7        archive.createEntry("entry1.bin", fi1, false,
 8                new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(),
 9                        new SevenZipAESEncryptionSettings("test1")));
10        archive.createEntry("entry2.bin", fi2, false,
11                new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(),
12                        new SevenZipAESEncryptionSettings("test2")));
13        archive.createEntry("entry3.bin", fi3, false,
14                new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(),
15                        new SevenZipAESEncryptionSettings("test3")));
16        archive.save(sevenZipFile);
17    }
18} catch (ioException ex) {
19}

7Z 아카이브 추출

이제 aspose.zip은 lzma, lzma2, bzip2 및 ppmd 압축 아카이브를 추출 할 수 있습니다.

다음 코드 예제는 7Z 아카이브를 디렉토리로 추출하는 방법을 보여줍니다.

1try (sevenziparchive archive = new sevenziparchive ( "archive.7z")) {
2    Archive.extractTodirectory ( "Extractionfolder");
3}

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.