2013-09-03 6 views
6

में मल्टीपार्ट संपीड़ित ज़िप फ़ाइल कैसे बना सकता हूं मुझे एक ज़िप (टैर, जीजे, 7z, आदि) फ़ाइल के अंदर एक निर्देशिका को संपीड़ित करने की आवश्यकता है। यह ठीक है लेकिन मुझे एक दूसरे से जुड़े मल्टीपार्ट ज़िप फ़ाइलों को बनाने की जरूरत है (जैसे file1.part1.zip, file1.part2.zip)मैं जावा

मैं जावा में मल्टीपार्ट ज़िप फ़ाइल कैसे बना सकता हूं? प्रत्येक भाग में अधिकतम आकार सीमा होनी चाहिए।

उत्तर

8

Zip4j पर जा सकते हैं ज़िप कर सकते हैं विभाजन ज़िप फ़ाइल के निर्माण का समर्थन करता है। यहाँ एक विभाजन ज़िप फ़ाइल बनाने में एक नमूना (नमूना Zip4j examples package से लिया)

ZipFile.createZipFile(File sourceFile, ZipParameters parameters, boolean splitArchive, long splitLength) 

एक विभाजन ज़िप फ़ाइल बनाने में विधि है। इस मामले में boolean splitArchive को सत्य पर सेट करना होगा। आप प्रत्येक स्प्लिट फ़ाइल (z01, z02, आदि) के लिए अधिकतम फ़ाइल आकार long splitLength

import java.io.File; 
import java.util.ArrayList; 

import net.lingala.zip4j.core.ZipFile; 
import net.lingala.zip4j.exception.ZipException; 
import net.lingala.zip4j.model.ZipParameters; 
import net.lingala.zip4j.util.Zip4jConstants; 

public class CreateSplitZipFile { 

    public CreateSplitZipFile() { 

     try { 
      // Initiate ZipFile object with the path/name of the zip file. 
      ZipFile zipFile = new ZipFile("c:\\ZipTest\\CreateSplitZipFile.zip"); 

      // Build the list of files to be added in the array list 
      // Objects of type File have to be added to the ArrayList 
      ArrayList filesToAdd = new ArrayList(); 
      filesToAdd.add(new File("c:\\ZipTest\\sample.txt")); 
      filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi")); 
      filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3")); 

      // Initiate Zip Parameters which define various properties such 
      // as compression method, etc. 
      ZipParameters parameters = new ZipParameters(); 

      // set compression method to store compression 
      parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); 

      // Set the compression level. This value has to be in between 0 to 9 
      parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); 

      // Create a split file by setting splitArchive parameter to true 
      // and specifying the splitLength. SplitLenth has to be greater than 
      // 65536 bytes 
      // Please note: If the zip file already exists, then this method throws an 
      // exception 
      zipFile.createZipFile(filesToAdd, parameters, true, 10485760); 
     } catch (ZipException e) { 
      e.printStackTrace(); 
     } 
    } 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     new CreateSplitZipFile(); 
    } 

} 
-4

इन विधि और प्रवाह का उपयोग हम फ़ाइल

private long totalFileSize = 0L; /* In bytes */ 
private long totalNumberFilesSelected = 0L; /* Total number of files selected */ 
private int partitionSize; /* In MegaBytes */ 
private int partitionSizeInBytes = 100000000; /* defaulted to 100 MB */ 
private int compressionLevel = 9; /* defaults to 9 (best) */ 
private String saveFileBase = ""; /* Zip file to save as */ 
private ArrayList fileInfoList; 
private ArrayList fileIndices = new ArrayList(); 

private int computeNumberOfArchives() 
private void createZipArchive() 
private void doZip() 

अधिक विवरण के लिए यू लिंक

http://www.codeproject.com/Articles/25453/Automating-Multipart-Zip-File-Creation

+2

कोड उदाहरण बेकार है। लेख सी # के बारे में है। स्रोत सूचीबद्ध नहीं है और पंजीकरण के बाद ही डाउनलोड किया जा सकता है। – Vadzim