SevenZipArchive
Inheritance: java.lang.Object
All Implemented Interfaces: com.aspose.zip.IArchive, java.lang.AutoCloseable
public class SevenZipArchive implements IArchive, AutoCloseable
Denna klass representerar en 7z-arkivfil. Använd den för att skapa och extrahera 7z-arkiv.
Konstruktörer
| Konstruktor | Beskrivning |
|---|---|
| SevenZipArchive() | Initierar en ny instans av klassen SevenZipArchive med valfria inställningar för dess poster. |
| SevenZipArchive(SevenZipEntrySettings newEntrySettings) | Initierar en ny instans av klassen SevenZipArchive med valfria inställningar för dess poster. |
| SevenZipArchive(InputStream sourceStream) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(InputStream sourceStream, String password) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(String path) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(String path, String password) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(InputStream sourceStream, SevenZipLoadOptions options) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(String path, SevenZipLoadOptions options) | Initierar en ny instans av klassen SevenZipArchive och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(String[] parts) | Initierar en ny instans av klassen SevenZipArchive från ett flervolyms 7z-arkiv och skapar en postlista som kan extraheras från arkivet. |
| SevenZipArchive(String[] parts, String password) | Initierar en ny instans av klassen SevenZipArchive från ett flervolyms 7z-arkiv och skapar en postlista som kan extraheras från arkivet. |
Metoder
SevenZipArchive()
public SevenZipArchive()
Initierar en ny instans av klassen SevenZipArchive med valfria inställningar för dess poster.
Följande exempel visar hur man komprimerar en enskild fil med standardinställningar: LZMA-kompression utan kryptering.
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { try (SevenZipArchive archive = new SevenZipArchive()) { archive.createEntry(“data.bin”, “file.dat”); archive.save(sevenZipFile); } } catch (IOException ex) { }
LZMA compression without encryption would be used.
### SevenZipArchive(SevenZipEntrySettings newEntrySettings) {#SevenZipArchive-com.aspose.zip.SevenZipEntrySettings-}
public SevenZipArchive(SevenZipEntrySettings newEntrySettings)
Initializes a new instance of the [SevenZipArchive](../../com.aspose.zip/sevenziparchive) class with optional settings for its entries.
The following example shows how to compress a single file with default settings: LZMA compression without encryption.
try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
try (SevenZipArchive archive = new SevenZipArchive()) {
archive.createEntry("data.bin", "file.dat");
archive.save(sevenZipFile);
}
} catch (IOException ex) {
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | komprimerings- och krypteringsinställningar som används för nyinlagda [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) objekt. Om de inte anges, kommer LZMA-komprimering utan kryptering att användas |
### SevenZipArchive(InputStream sourceStream) {#SevenZipArchive-java.io.InputStream-}
```
public SevenZipArchive(InputStream sourceStream)
```
Initierar en ny instans av klassen [SevenZipArchive](../../com.aspose.zip/sevenziparchive) och skapar en postlista som kan extraheras från arkivet.
```
try (SevenZipArchive archive = new SevenZipArchive(new FileInputStream(“archive.7z”))) { archive.extractToDirectory("C:\\extracted"); } catch (FileNotFoundException ex) { }
This constructor does not decompress any entry. See [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) method for decompressing.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | the source of the archive |
### SevenZipArchive(InputStream sourceStream, String password) {#SevenZipArchive-java.io.InputStream-java.lang.String-}
public SevenZipArchive(InputStream sourceStream, String password)
Initializes a new instance of the [SevenZipArchive](../../com.aspose.zip/sevenziparchive) class and composes an entry list can be extracted from the archive.
try (SevenZipArchive archive = new SevenZipArchive(new FileInputStream("archive.7z"))) {
archive.extractToDirectory("C:\\extracted");
} catch (FileNotFoundException ex) {
}
```
Den här konstruktorn dekomprimerar inte någon post. Se [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) metod för dekomprimering.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| sourceStream | java.io.InputStream | källan till arkivet |
| lösenord | java.lang.String | valfritt lösenord för dekryptering. Om filnamn är krypterade måste det finnas. |
### SevenZipArchive(String path) {#SevenZipArchive-java.lang.String-}
```
public SevenZipArchive(String path)
```
Initierar en ny instans av klassen [SevenZipArchive](../../com.aspose.zip/sevenziparchive) och skapar en postlista som kan extraheras från arkivet.
```
try (SevenZipArchive archive = new SevenZipArchive(“archive.7z”)) { archive.extractToDirectory("C:\\extracted"); } catch (FileNotFoundException ex) { }
This constructor does not decompress any entry. See [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) method for decompressing.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the fully qualified or the relative path to the archive file |
### SevenZipArchive(String path, String password) {#SevenZipArchive-java.lang.String-java.lang.String-}
public SevenZipArchive(String path, String password)
Initializes a new instance of the [SevenZipArchive](../../com.aspose.zip/sevenziparchive) class and composes an entry list can be extracted from the archive.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
archive.extractToDirectory("C:\\extracted");
} catch (FileNotFoundException ex) {
}
```
Den här konstruktorn dekomprimerar inte någon post. Se [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) metod för dekomprimering.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| path | java.lang.String | den fullständiga eller relativa sökvägen till arkivfilen |
| lösenord | java.lang.String | valfritt lösenord för dekryptering. Om filnamn är krypterade måste det finnas. |
### SevenZipArchive(InputStream sourceStream, SevenZipLoadOptions options) {#SevenZipArchive-java.io.InputStream-com.aspose.zip.SevenZipLoadOptions-}
```
public SevenZipArchive(InputStream sourceStream, SevenZipLoadOptions options)
```
Initierar en ny instans av klassen [SevenZipArchive](../../com.aspose.zip/sevenziparchive) och skapar en postlista som kan extraheras från arkivet.
Extrahera ett krypterat arkiv. Tillåt upp till 60 sekunder att fortsätta, avbryt efter den perioden.
```
try (CancellationFlag cf = new CancellationFlag()) { SevenZipLoadOptions options = new SevenZipLoadOptions(); options.setDecryptionPassword(“Top$ecr3t”); options.setCancellationFlag(cf); cf.cancelAfter(TimeUnit.SECONDS.toMillis(60)); try (SevenZipArchive a = new SevenZipArchive(new FileInputStream(“archive.7z”), options)) { a.extractToDirectory(“C:\extracted”); } catch (IOException ex) { } }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | The source of the archive. |
| options | [SevenZipLoadOptions](../../com.aspose.zip/sevenziploadoptions) | Options to load existing archive with.
This constructor does not decompress any entry. See [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) method for decompressing. |
### SevenZipArchive(String path, SevenZipLoadOptions options) {#SevenZipArchive-java.lang.String-com.aspose.zip.SevenZipLoadOptions-}
public SevenZipArchive(String path, SevenZipLoadOptions options)
Initializes a new instance of the [SevenZipArchive](../../com.aspose.zip/sevenziparchive) class and composes an entry list can be extracted from the archive.
Extract an encrypted archive. Allow up to 60 seconds to proceed, cancel after that period.
try (CancellationFlag cf = new CancellationFlag()) {
SevenZipLoadOptions options = new SevenZipLoadOptions();
options.setDecryptionPassword("Top$ecr3t");
options.setCancellationFlag(cf);
cf.cancelAfter(TimeUnit.SECONDS.toMillis(60));
try (SevenZipArchive a = new SevenZipArchive(new FileInputStream("archive.7z"), options)) {
a.extractToDirectory("C:\\extracted");
} catch (IOException ex) {
}
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| path | java.lang.String | Den fullständiga eller relativa sökvägen till arkivfilen. |
| | options | [SevenZipLoadOptions](../../com.aspose.zip/sevenziploadoptions) | Alternativ för att läsa in befintligt arkiv med. |
Den här konstruktorn dekomprimerar inte någon post. Se [extractToDirectory(String, String)](../../com.aspose.zip/sevenziparchive\#extractToDirectory-String--String-) metod för dekomprimering. |
### SevenZipArchive(String[] parts) {#SevenZipArchive-java.lang.String---}
```
public SevenZipArchive(String[] parts)
```
Initierar en ny instans av klassen [SevenZipArchive](../../com.aspose.zip/sevenziparchive) från ett flervolyms 7z-arkiv och skapar en postlista som kan extraheras från arkivet.
```
try (SevenZipArchive archive = new SevenZipArchive(new String[] { “multi.7z.001”, “multi.7z.002”, “multi.7z.003” } )) { archive.extractToDirectory("C:\\extracted"); }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| parts | java.lang.String[] | paths to each segment of multi-volume 7z archive respecting order |
### SevenZipArchive(String[] parts, String password) {#SevenZipArchive-java.lang.String---java.lang.String-}
public SevenZipArchive(String[] parts, String password)
Initializes a new instance of the [SevenZipArchive](../../com.aspose.zip/sevenziparchive) class from multi-volume 7z archive and composes an entry list can be extracted from the archive.
try (SevenZipArchive archive = new SevenZipArchive(new String[] { "multi.7z.001", "multi.7z.002", "multi.7z.003" } )) {
archive.extractToDirectory("C:\\extracted");
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| delar | java.lang.String[] | sökvägar till varje segment av ett flervolyms 7z-arkiv i rätt ordning |
| lösenord | java.lang.String | valfritt lösenord för dekryptering. Om filnamn är krypterade måste det finnas. |
### close() {#close--}
```
public void close()
```
### createEntries(File directory) {#createEntries-java.io.File-}
```
public final SevenZipArchive createEntries(File directory)
```
Lägger till alla filer och kataloger rekursivt i den angivna katalogen i arkivet.
```
try (SevenZipArchive archive = new SevenZipArchive()) { File folder = new File(“C:\folder”); archive.createEntries(folder); archive.save(“folder.7z”); }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | directory to compress |
**Returns:**
[SevenZipArchive](../../com.aspose.zip/sevenziparchive) - the archive with entries composed
### createEntries(File directory, boolean includeRootDirectory) {#createEntries-java.io.File-boolean-}
public final SevenZipArchive createEntries(File directory, boolean includeRootDirectory)
Adds to the archive all files and directories recursively in the directory given.
try (SevenZipArchive archive = new SevenZipArchive()) {
File folder = new File("C:\\folder");
archive.createEntries(folder);
archive.save("folder.7z");
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| directory | java.io.File | katalog att komprimera |
| includeRootDirectory | boolean | indikerar om rotkatalogen själv ska inkluderas eller inte |
**Returns:**
[SevenZipArchive](../../com.aspose.zip/sevenziparchive) - the archive with entries composed
### createEntries(String sourceDirectory) {#createEntries-java.lang.String-}
```
public final SevenZipArchive createEntries(String sourceDirectory)
```
Lägger till alla filer och kataloger rekursivt i den angivna katalogen i arkivet.
Skapa 7z-arkiv med LZMA-komprimering.
```
try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings))) { archive.createEntries(“C:\folder”); archive.save(“folder.7z”); }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | directory to compress |
**Returns:**
[SevenZipArchive](../../com.aspose.zip/sevenziparchive) - the archive with entries composed
### createEntries(String sourceDirectory, boolean includeRootDirectory) {#createEntries-java.lang.String-boolean-}
public final SevenZipArchive createEntries(String sourceDirectory, boolean includeRootDirectory)
Adds to the archive all files and directories recursively in the directory given.
Compose 7z archive with LZMA compression.
try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
archive.createEntries("C:\\folder");
archive.save("folder.7z");
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| sourceDirectory | java.lang.String | katalog att komprimera |
| includeRootDirectory | boolean | indikerar om rotkatalogen själv ska inkluderas eller inte |
**Returns:**
[SevenZipArchive](../../com.aspose.zip/sevenziparchive) - the archive with entries composed
### createEntry(String name, File file) {#createEntry-java.lang.String-java.io.File-}
```
public final SevenZipArchiveEntry createEntry(String name, File file)
```
Skapar en enskild post i arkivet.
Skapa arkivet med poster krypterade med olika lösenord för varje.
```
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { File fi1 = new File(“data1.bin”); File fi2 = new File(“data2.bin”); File fi3 = new File(“data3.bin”);
try (SevenZipArchive archive = new SevenZipArchive()) { archive.createEntry(“entry1.bin”, fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test1”))); archive.createEntry(“entry2.bin”, fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test2”))); archive.createEntry(“entry3.bin”, fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test3”))); archive.save(sevenZipFile); } } catch (IOException ex) { }
The entry name is solely set within `name` parameter. The file name provided in `file` parameter does not affect the entry name.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| file | java.io.File | the metadata of file to be compressed |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, File file, boolean openImmediately) {#createEntry-java.lang.String-java.io.File-boolean-}
public final SevenZipArchiveEntry createEntry(String name, File file, boolean openImmediately)
Creates a single entry within the archive.
Compose archive with entries encrypted with different passwords each.
try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
File fi1 = new File("data1.bin");
File fi2 = new File("data2.bin");
File fi3 = new File("data3.bin");
try (SevenZipArchive archive = new SevenZipArchive()) {
archive.createEntry("entry1.bin", fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
archive.createEntry("entry2.bin", fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test2")));
archive.createEntry("entry3.bin", fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test3")));
archive.save(sevenZipFile);
}
} catch (IOException ex) {
}
```
Postnamnet sätts enbart i `name`-parametern. Filnamnet som anges i `file`-parametern påverkar inte postnamnet.
Om filen öppnas omedelbart med `openImmediately`-parametern blir den låst tills arkivet sparas.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| namn | java.lang.String | namnet på posten |
| file | java.io.File | metadata för filen som ska komprimeras |
| openImmediately | boolean | true, om filen ska öppnas omedelbart, annars öppnas filen vid arkivsparning |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, File file, boolean openImmediately, SevenZipEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.io.File-boolean-com.aspose.zip.SevenZipEntrySettings-}
```
public final SevenZipArchiveEntry createEntry(String name, File file, boolean openImmediately, SevenZipEntrySettings newEntrySettings)
```
Skapar en enskild post i arkivet.
Skapa arkivet med poster krypterade med olika lösenord för varje.
```
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { File fi1 = new File(“data1.bin”); File fi2 = new File(“data2.bin”); File fi3 = new File(“data3.bin”);
try (SevenZipArchive archive = new SevenZipArchive()) { archive.createEntry(“entry1.bin”, fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test1”))); archive.createEntry(“entry2.bin”, fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test2”))); archive.createEntry(“entry3.bin”, fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings(“test3”))); archive.save(sevenZipFile); } } catch (IOException ex) { }
The entry name is solely set within `name` parameter. The file name provided in `file` parameter does not affect the entry name.
If the file is opened immediately with `openImmediately` parameter it becomes blocked until archive is saved.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| file | java.io.File | the metadata of file to be compressed |
| openImmediately | boolean | true, if open the file immediately, otherwise open the file on archive saving |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | compression and encryption settings used for added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) item. Individual compression settings is ignored in case of solid compression, see `SevenZipEntrySettings.Solid`([SevenZipEntrySettings.getSolid](../../com.aspose.zip/sevenzipentrysettings\#getSolid)/[SevenZipEntrySettings.setSolid](../../com.aspose.zip/sevenzipentrysettings\#setSolid)). |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, InputStream source) {#createEntry-java.lang.String-java.io.InputStream-}
public final SevenZipArchiveEntry createEntry(String name, InputStream source)
Creates a single entry within the archive.
Compose 7z archive with LZMA compression and encryption of all entries.
try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings("p@s$")))) {
archive.createEntry("data.bin", new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF} ));
archive.save("archive.7z");
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| namn | java.lang.String | namnet på posten |
| source | java.io.InputStream | indataströmmen för posten |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, InputStream source, SevenZipEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.io.InputStream-com.aspose.zip.SevenZipEntrySettings-}
```
public final SevenZipArchiveEntry createEntry(String name, InputStream source, SevenZipEntrySettings newEntrySettings)
```
Skapar en enskild post i arkivet.
Skapa 7z-arkiv med LZMA-komprimering och kryptering av alla poster.
```
try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings(“p@s$”)))) { archive.createEntry(“data.bin”, new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF} )); archive.save(“archive.7z”); }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| source | java.io.InputStream | the input stream for the entry |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | compression and encryption settings used for added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) item. Individual compression settings is ignored in case of solid compression, see `SevenZipEntrySettings.Solid`([SevenZipEntrySettings.getSolid](../../com.aspose.zip/sevenzipentrysettings\#getSolid)/[SevenZipEntrySettings.setSolid](../../com.aspose.zip/sevenzipentrysettings\#setSolid)). |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, InputStream source, SevenZipEntrySettings newEntrySettings, File file) {#createEntry-java.lang.String-java.io.InputStream-com.aspose.zip.SevenZipEntrySettings-java.io.File-}
public final SevenZipArchiveEntry createEntry(String name, InputStream source, SevenZipEntrySettings newEntrySettings, File file)
Creates a single entry within the archive.
Compose archive with LZMA compressed encrypted entry.
try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
try (SevenZipArchive archive = new SevenZipArchive()) {
archive.createEntry("entry1.bin", new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF}), new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings("test1")), new File("data1.bin"));
archive.save(sevenZipFile);
}
} catch (IOException ex) {
}
```
Postnamnet sätts enbart i `name`-parametern. Filnamnet som anges i `file`-parametern påverkar inte postnamnet.
`file` kan referera till en katalog.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| namn | java.lang.String | namnet på posten |
| source | java.io.InputStream | indataströmmen för posten |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | komprimerings- och krypteringsinställningar som används för tillagd [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry)-post. Individuella komprimeringsinställningar ignoreras vid solid komprimering, se `SevenZipEntrySettings.Solid`([SevenZipEntrySettings.getSolid](../../com.aspose.zip/sevenzipentrysettings\#getSolid)/[SevenZipEntrySettings.setSolid](../../com.aspose.zip/sevenzipentrysettings\#setSolid)). |
| file | java.io.File | metadata för fil eller mapp som ska komprimeras |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, String path) {#createEntry-java.lang.String-java.lang.String-}
```
public final SevenZipArchiveEntry createEntry(String name, String path)
```
Skapar en enskild post i arkivet.
```
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings))) { archive.createEntry(“data.bin”, “file.dat”); archive.save(sevenZipFile); } } catch (IOException ex) { }
The entry name is solely set within `name` parameter. The file name provided in `path` parameter does not affect the entry name.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| path | java.lang.String | the fully qualified name of the new file, or the relative file name to be compressed |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, String path, boolean openImmediately) {#createEntry-java.lang.String-java.lang.String-boolean-}
public final SevenZipArchiveEntry createEntry(String name, String path, boolean openImmediately)
Creates a single entry within the archive.
try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
archive.createEntry("data.bin", "file.dat");
archive.save(sevenZipFile);
}
} catch (IOException ex) {
}
```
Postnamnet sätts enbart i `name`-parametern. Filnamnet som anges i `path`-parametern påverkar inte postnamnet.
Om filen öppnas omedelbart med `openImmediately`-parametern blir den låst tills arkivet sparas.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| namn | java.lang.String | namnet på posten |
| path | java.lang.String | det fullständigt kvalificerade namnet på den nya filen, eller det relativa filnamnet som ska komprimeras |
| openImmediately | boolean | true, om filen ska öppnas omedelbart, annars öppnas filen vid arkivsparning |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Seven Zip entry instance
### createEntry(String name, String path, boolean openImmediately, SevenZipEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.lang.String-boolean-com.aspose.zip.SevenZipEntrySettings-}
```
public final SevenZipArchiveEntry createEntry(String name, String path, boolean openImmediately, SevenZipEntrySettings newEntrySettings)
```
Skapar en enskild post i arkivet.
```
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings))) { archive.createEntry(“data.bin”, “file.dat”); archive.save(sevenZipFile); } } catch (IOException ex) { }
The entry name is solely set within `name` parameter. The file name provided in `path` parameter does not affect the entry name.
If the file is opened immediately with `openImmediately` parameter it becomes blocked until archive is saved.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | the name of the entry |
| path | java.lang.String | the fully qualified name of the new file, or the relative file name to be compressed |
| openImmediately | boolean | true, if open the file immediately, otherwise open the file on archive saving |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | compression and encryption settings used for added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) item. Individual compression settings is ignored in case of solid compression, see `SevenZipEntrySettings.Solid`([SevenZipEntrySettings.getSolid](../../com.aspose.zip/sevenzipentrysettings\#getSolid)/[SevenZipEntrySettings.setSolid](../../com.aspose.zip/sevenzipentrysettings\#setSolid)). |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - Zip entry instance
### createEntry(String name, Supplier<InputStream> streamProvider) {#createEntry-java.lang.String-java.util.function.Supplier-java.io.InputStream--}
public final SevenZipArchiveEntry createEntry(String name, Supplier
Create a single entry within the archive.
Compose archive with LZMA2 compressed encrypted entry.
System.Func<Stream> provider = delegate(){ return new MemoryStream(new byte[]{0xFF, 0x00}); };
using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
using (var archive = new SevenZipArchive())
{
archive.CreateEntry("entry1.bin", provider, new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
archive.Save(sevenZipFile);
}
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| namn | java.lang.String | Postens namn. |
| streamProvider | java.util.function.Supplier<java.io.InputStream> | Metoden som tillhandahåller inmatningsström för posten. |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - SevenZip entry instance.
### createEntry(String name, Supplier<InputStream> streamProvider, SevenZipEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.util.function.Supplier-java.io.InputStream--com.aspose.zip.SevenZipEntrySettings-}
```
public final SevenZipArchiveEntry createEntry(String name, Supplier<InputStream> streamProvider, SevenZipEntrySettings newEntrySettings)
```
Skapa en enskild post i arkivet.
Skapa arkiv med LZMA2-komprimerad krypterad post.
```
System.Func<Stream> provider = delegate(){ return new MemoryStream(new byte[]{0xFF, 0x00}); }; using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create)) { using (var archive = new SevenZipArchive()) { archive.CreateEntry("entry1.bin", provider, new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(), new SevenZipAESEncryptionSettings("test1"))); archive.Save(sevenZipFile); } }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| streamProvider | java.util.function.Supplier<java.io.InputStream> | The method providing input stream for the entry. |
| newEntrySettings | [SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) | Compression and encryption settings used for added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) item. Individual compression settings is ignored in case of solid compression, see `SevenZipEntrySettings.Solid`([SevenZipEntrySettings.getSolid](../../com.aspose.zip/sevenzipentrysettings\#getSolid)/[SevenZipEntrySettings.setSolid](../../com.aspose.zip/sevenzipentrysettings\#setSolid)). |
**Returns:**
[SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) - SevenZip entry instance.
### extractToDirectory(String destinationDirectory) {#extractToDirectory-java.lang.String-}
public final void extractToDirectory(String destinationDirectory)
Extracts all the files in the archive to the directory provided.
try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
archive.extractToDirectory("C:\\extracted");
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| | destinationDirectory | java.lang.String | sökvägen till katalogen där de extraherade filerna ska placeras. |
Om katalogen inte finns, kommer den att skapas |
### extractToDirectory(String destinationDirectory, String password) {#extractToDirectory-java.lang.String-java.lang.String-}
```
public final void extractToDirectory(String destinationDirectory, String password)
```
Extraherar alla filer i arkivet till den angivna katalogen.
```
try (SevenZipArchive archive = new SevenZipArchive(“archive.7z”)) { archive.extractToDirectory("C:\\extracted"); }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationDirectory | java.lang.String | the path to the directory to place the extracted files in
If the directory does not exist, it will be created. |
| password | java.lang.String | optional password for content decryption.
`password` is used for content decryption only. If file names are encrypted provide password in [SevenZipArchive(String, String)](../../com.aspose.zip/sevenziparchive\#SevenZipArchive-String--String-) or [SevenZipArchive(java.io.InputStream, String)](../../com.aspose.zip/sevenziparchive\#SevenZipArchive-java.io.InputStream--String-) constructor. |
### getEntries() {#getEntries--}
public final List
Gets entries of [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) type constituting the archive.
**Returns:**
java.util.List<com.aspose.zip.SevenZipArchiveEntry> - entries of [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) type constituting the archive
### getFileEntries() {#getFileEntries--}
public final Iterable
Gets entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the 7z archive.
**Returns:**
java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the 7z archive
### getFormat() {#getFormat--}
public final ArchiveFormat getFormat()
Gets the archive format.
**Returns:**
[ArchiveFormat](../../com.aspose.zip/archiveformat) - the archive format
### getNewEntrySettings() {#getNewEntrySettings--}
public final SevenZipEntrySettings getNewEntrySettings()
Compression and encryption settings used for newly added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) items.
**Returns:**
[SevenZipEntrySettings](../../com.aspose.zip/sevenzipentrysettings) - compression and encryption settings used for newly added [SevenZipArchiveEntry](../../com.aspose.zip/sevenziparchiveentry) items
### save(OutputStream output) {#save-java.io.OutputStream-}
public final void save(OutputStream output)
Saves 7z archive to the stream provided.
try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
try (FileInputStream source = new FileInputStream("data.bin")) {
try (SevenZipArchive archive = new SevenZipArchive()) {
archive.createEntry("data", source);
archive.save(sevenZipFile);
}
}
} catch (IOException ex) {
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| utdata | java.io.OutputStream | målström |
### save(OutputStream output, SevenZipArchiveSaveOptions saveOptions) {#save-java.io.OutputStream-com.aspose.zip.SevenZipArchiveSaveOptions-}
```
public final void save(OutputStream output, SevenZipArchiveSaveOptions saveOptions)
```
Sparar 7z-arkivet till den angivna strömmen.
```
try (FileOutputStream sevenZipFile = new FileOutputStream(“archive.7z”)) { try (FileInputStream source = new FileInputStream(“data.bin”)) { try (SevenZipArchive archive = new SevenZipArchive()) { archive.createEntry("data", source); archive.save(sevenZipFile); } } } catch (IOException ex) { }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| output | java.io.OutputStream | destination stream |
| saveOptions | [SevenZipArchiveSaveOptions](../../com.aspose.zip/sevenziparchivesaveoptions) | Options for archive saving. |
### save(String destinationFileName) {#save-java.lang.String-}
public final void save(String destinationFileName)
Saves archive to a destination file provided.
using (FileStream source = File.Open("data.bin", FileMode.Open, FileAccess.Read))
{
using (var archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings())))
{
archive.CreateEntry("data", source);
archive.Save("archive.7z");
}
}
```
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| | destinationFileName | java.lang.String | Sökvägen till arkivet som ska skapas. Om det angivna filnamnet pekar på en befintlig fil kommer den att skrivas över. |
Det är möjligt att spara ett arkiv till samma sökväg som det laddades från. Detta rekommenderas dock inte eftersom detta tillvägagångssätt använder kopiering till en temporär fil. |
### save(String destinationFileName, SevenZipArchiveSaveOptions saveOptions) {#save-java.lang.String-com.aspose.zip.SevenZipArchiveSaveOptions-}
```
public final void save(String destinationFileName, SevenZipArchiveSaveOptions saveOptions)
```
Sparar arkivet till den angivna destinationsfilen.
```
try (FileInputStream source = new FileInputStream(“data.bin”)) { try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings))) { archive.createEntry("data", source); archive.save(“archive.7z”); } } catch (IOException ex) { }
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationFileName | java.lang.String | the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten. |
| saveOptions | [SevenZipArchiveSaveOptions](../../com.aspose.zip/sevenziparchivesaveoptions) | Options for archive saving.
It is possible to save an archive to the same path as it was loaded from. However, this is not recommended because this approach uses copying to a temporary file. |
### saveSplit(String destinationDirectory, SplitSevenZipArchiveSaveOptions options) {#saveSplit-java.lang.String-com.aspose.zip.SplitSevenZipArchiveSaveOptions-}
public final void saveSplit(String destinationDirectory, SplitSevenZipArchiveSaveOptions options)
Saves multi-volume archive to destination directory provided.
try (SevenZipArchive archive = new SevenZipArchive()) {
archive.createEntry("entry.bin", "data.bin");
archive.saveSplit("C:\\Folder", new SplitSevenZipArchiveSaveOptions("volume", 65536));
}
```
Denna metod sammansätter flera `(n)`-filer filename.7z.001, filename.7z.002, ..., filename.7z.(n).
Det går inte att göra ett befintligt arkiv flervolym.
**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| destinationDirectory | java.lang.String | sökvägen till katalogen där arkivsegment ska skapas |
| options | [SplitSevenZipArchiveSaveOptions](../../com.aspose.zip/splitsevenziparchivesaveoptions) | alternativ för arkivsparning, inklusive filnamn |