Java?????????????????

??

???????Java API??????????????????????????ZIP??????????????????????????? 1???????????????????????????????zip???????????????????????????????????

Java??????zip???????Java????????????????

Aspose.Zip API???????????????????????????????????????????????????????????????????????????????????????

???????

?????????

??: Java????????????

  1. ?????????????zip????????????????? 2? ???????????????????????????????????
  2. Archive??????????????? ArchiveEntrySettings????????????????
  3. archive.createentry??????????????2????????????????????
  4. archive.save?????????????????zip??????1?????????????????????
 1try(fileoutputStream zipfile = new fileoutputStream(datadir + "compresssinglefile_out.zip")){
 2    //???????????????
 3    try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
 4        try(Archive archive = new Archive(new ArchiveEntrySettings())){
 5            archive.createentry( "alice29.txt"?source1);
 6            archive.save(zipfile);
 7        }
 8    }
 9} catch(ioException ex){
10    System.out.println(ex);
11}

????????????

??: Java???????????

1.??zip????????????????????????????? 2????????????????????????????????? 3??????2??????????????????????????? 4. ?????????????????????? 5. archive.createentry??????????????2???????3???????????????????? 6. archivesaveoptions????????????????? 7. archive.save?????????????????zip???????????????archivesaveoptions????????????????????????????

 1try(fileoutputStream zipfile = new fileoutputStream(datadir + "compresssinglefile_out.zip")){
 2    try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
 3        try(fileinputStream source2 = new fileinputStream(datadir + "asyoulik.txt")){
 4            try(Archive archive = new Archive(new ArchiveEntrySettings())){
 5                archive.createentry( "alice29.txt"?source1);
 6                archive.createentry( "asyoulik.txt"?source2);
 7                ArchivesAveOptions options = new archivesaveoptions();
 8                options.SetEncoding(StandardCharsets.us_ascii);
 9                options.setArchiveComment(?????????????2?????????);
10                archive.save(zipfile?options);
11            }
12        }
13    }
14} catch(ioException ex){
15    System.out.println(ex);
16}

????????????????

java ???????????????? 1.??zip?????????????????????????????? 2???????????? ????????????????????? 3. ???? 2?????????????????????????? 4. ?????????????????????? 5. archive.createentry??????????????2???????3???????????????????? 6. archivesaveoptions????????????????? 7. archive.save?????????????????zip???????????????archivesaveoptions????????????????????????????

 1try(fileoutputStream zipfile = new fileoutputStream(datadir + "compressfilesbyfileinfo_out.zip")){
 2    ????fi1 = new file(datadir + "alice29.txt");
 3    ????fi2 = new file(datadir + "fields.c");
 4    try(archive archive = new archive()){
 5        archive.createentry( "alice29.txt"?fi1);
 6        archive.createentry( "fields.c"?fi2);
 7        ArchivesAveOptions options = new archivesaveoptions();
 8        options.SetEncoding(StandardCharsets.us_ascii);
 9        archive.save(zipfile?options);
10    }
11} catch(IOException??????){
12    System.out.println(ex);
13}

??????????????????

??: java???????????????????????

1.??zip?????????????????????????????? 2? ???????????????????????????????????? 3. ArchiveEntrySettings??????????????? StoreCompressionsettings???????????????? 4. ?????????????????????????????????archiveentrysettings???????????????? 5? archive.createentry??????????????2????????????????? 6. archivesaveoptions???????????? archivesaveoptions.setencoding?????????stardandcharsets.us_ascii????????????? 7. archive.save?????????????????zip???????????????archivesaveoptions????????????????????????????

 1try(fileoutputStream zipfile = new fileoutputStream(datadir + "storemultiplefileswithoutcompression_out.zip"){
 2    ????fi1 = new file(datadir + "alice29.txt");
 3    ????fi2 = new file(datadir + "fields.c");
 4    try(Archive Archive = new Archive(new ArchiveEntrySettings(new StoreCompressionsettings())){
 5        archive.createentry( "alice29.txt"?fi1);
 6        archive.createentry( "fields.c"?fi2);
 7        ArchivesAveOptions options = new archivesaveoptions();
 8        options.SetEncoding(StandardCharsets.us_ascii);
 9        archive.save(zipfile?options);
10    }
11} catch(IOException??????){
12    System.out.println(ex);
13}

??????????????????

????:?????????Java??????????????

1.??zip?????????????????????????????? 2????????????2???????????????????????????????????? 3. ?????????????????????? 4. archive.createentry??????????????2???????????????????? 5. PARLELALELOPTIONS???????????? Paralleloptions.setParallecompressInmemory??????????[ParallecompressionMode.always **??????? 6. archivesaveoptions???????????? archivesaveoptions.setparalleloptions????????????????????????????????? 7. archive.save?????????????????zip???????????????archivesaveoptions????????????????????????????

 1try(fileoutputStream zipfile = new fileoutputStream(datadir + "?????ParallelismTocopressfiles_out.zip"){
 2    try(fileinputStream source1 = new fileinputStream(datadir + "alice29.txt")){
 3        try(fileinputStream source2 = new fileinputStream(datadir + "asyoulik.txt")){
 4            try(Archive archive = new Archive(new ArchiveEntrySettings())){
 5                archive.createentry( "alice29.txt"?source1);
 6                archive.createentry( "asyoulik.txt"?source2);
 7                Paralleloptions parlalEloptions = new Paralleloptions();
 8                paralleloptions.setParallecompressinmemory(parallecompressionMode.always);
 9                ArchivesAveOptions options = new archivesaveoptions();
10                options.setParalleloptions(Paralleloptions);
11                options.SetEncoding(StandardCharsets.us_ascii);
12                options.setArchiveComment(?????????????2?????????);
13                archive.save(zipfile?options);
14            }
15        }
16    }
17} catch(ioException ex){
18    System.out.println(ex);
19}

zip???????LZMA??

lempel � ziv � markov??????????(lzma)?????????????????????????????????�LZMA???????????????????????????????????? ZIP???????LZMA??????ZIP?????LZMA???????????????????????????Aspose.Zip API?????LZMA?????????????

??:java ?????zip???????LZMA??

1.??zip?????????????????????????????? 2? archiveentrysettings??????????????? lzmacompressionsettings???????????????? 3. ???????????????????????????ArchiveEntrySettings????????????? 4. archive.createentry??????????????????????????????????????? 5? archive.save?????????????????zip????

1try(fileoutputStream zipfile = new fileoutputStream(datadir + "lzmacompression_out.zip")){
2    try(Archive Archive = new Archive(new ArchiveEntrySettings(new lzmacompressionsettings())){
3        archive.createentry( "sample.txt"?datadir + "sample.txt");
4        archive.save(zipfile);
5    }
6} catch(IOException??????){
7    System.out.println(ex);
8}

zip???????bzip2??

BZIP2????????ZIP?????BZIP2??????????????????�?????????Aspose.Zip API?????BZIP2?????????????

??:java ?????zip???????zip???????bzip2??

1.??zip?????????????????????????????? 2? archiveentrysettings??????????????? bzip2compressionsettings???????????????? 4. ???????????????????????????archiveentrysettings????????????? 5. archive.createentry??????????????????????????????????????? 6. archive.save?????????????????zip????

1try(fileoutputStream zipfile = new fileoutputStream(datadir + "bzip2compression_out.zip")){
2    try(Archive Archive = new Archive(new ArchiveEntrySettings(new bzip2Compressionsettings())){
3        archive.createentry( "sample.txt"?datadir + "sample.txt");
4        archive.save(zipfile);
5    }
6} catch(IOException??????){
7    System.out.println(ex);
8}

????????

??????????????????

 1try(fileinputStream fs = new fileInputStream(datadir + "compressSinglefile_out.zip")){
 2    try(Archive Archive = new Archive(fs)){
 3        int []?????ready = new int [] {0};
 4        archive.getEntries()?get(0).setExtractionProgressed(new event <prowresventargs>(){
 5            @???????
 6            public void invoke(Object sender?progresseventargs progresseventargs){
 7                int?????=(int)((100 * progresseventargs.getproceedbytes()))
 8                        /((ArchiveEntry)???).getunCompressedSize());
 9                if(?????>???????[0])
10                {
11                    System.out.println(????? + "%??");
12                    PercentReady [0] =?????;
13                }
14            }
15        });
16        archive.getentries()?get(0).extrage(datadir + "alice_extracted_out.txt");
17    }
18} catch(ioException ex){
19    System.out.println(ex);
20}

??????????????????

 1try(fileInputStream fs = new fileInputStream(datadir + "compressMultipleFiles_out.zip")){
 2    stringbuilder sb = new StringBuilder( "?????:");
 3    int []?????ready = new int [] {0};
 4    archiveloadoptions options = new archiveloadoptions();
 5    options.setEntryListed(new event <Entereventargs>(){
 6        @???????
 7        public void invoke(Object sender?entereventargs entereventargs){
 8            sb.append(entereventargs.getentry()?getname())?append( "?");
 9        }
10    });
11    options.setEntryExtractionProgressed(???????<ProgressEventargs>(){
12        @???????
13        public void invoke(Object sender?progresseventargs progresseventargs){
14            int?????=(int)((100 * progresseventargs.getproceedbytes()))
15                    /((ArchiveEntry)???).getunCompressedSize());
16            if(?????>???????[0])
17            {
18                System.out.println(????? + "%??");
19                PercentReady [0] =?????;
20            }
21        }
22    });
23    try(Archive Archive = new Archive(fs?options)){
24        System.out.println(sb.substring(0?sb.length()-2));
25        try(fileoutputStream??= new fileoutputStream(datadir + "alice_extracted_out.txt")){
26            try(inputstream decompressed = archive.getentries()?get(0).open()){
27                byte [] buffer = new byte [8192];
28                int bytesRead;
29                while(0 <(bytesread = decompressed.read(buffer?0?buffer.length))){
30                    ?????.write(buffer?0?bytesread);
31                }
32                //???????????????????????????
33            }
34        }
35        ?????Ready [0] = 0;
36        archive.getEntries()?get(1).extract(datadir + "asyoulik_extracted_out.txt");
37    }
38} catch(ioException ex){
39    System.out.println(ex);
40}

?????????????????????

 1try(fileinputStream zipfile = new fileinputStream(datadir + "storemultiplefileswithoutcompression_out.zip"){
 2    try(Archive archive = new Archive(zipfile))){
 3        try(fileoutputStream??= new fileoutputStream(datadir + "alice_extracted_store_out.txt")){
 4            try(inputstream stored = archive.getentries()?get(0).open()){
 5                byte [] buffer = new byte [8192];
 6                int bytesRead;
 7                while(0 <(bytesread = stored.read(buffer?0?buffer.length))){
 8                    ?????.write(buffer?0?bytesread);
 9                }
10                //??????????????????????????????
11            }
12        }
13        try(fileoutputStream??= new fileoutputStream(datadir + "asyoulik_extracted_store_out.txt")){
14            try(inputstream stored = archive.getentries()?get(1).open()){
15                byte [] buffer = new byte [8192];
16                int bytesRead;
17                while(0 <(bytesread = stored.read(buffer?0?buffer.length))){
18                    ?????.write(buffer?0?bytesread);
19                }
20                //??????????????????????????????
21            }
22        }
23    }
24} catch(ioException ex){
25    System.out.println(ex);
26}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.