2010-08-08 7 views
6

मेरे पास 7zip संग्रह है जिसमें कुछ सौ फ़ाइलें अलग-अलग निर्देशिकाओं में विभाजित हैं। लक्ष्य इसे एफ़टीपी सर्वर से डाउनलोड करना है और फिर इसे फोन पर निकालना है।Android में 7zip संग्रह को अनजिप कैसे करें?

मेरी समस्या यह है कि 7zip एसडीके में बहुत कुछ नहीं है। मैं 7z फ़ाइलों के डिकंप्रेशन के संबंध में उदाहरण, ट्यूटोरियल और स्निपेट ढूंढ रहा हूं।

(Intent के माध्यम से विसंपीड़न केवल एक माध्यमिक विकल्प है)

+0

7-ज़िप ट्यूटोरियल की एक सूची this page के नीचे है। – gregS

+0

उत्तर के लिए धन्यवाद, लेकिन 7zip पेज पर लिंक काफी पुराने हैं और मेरे लिए उपयोग योग्य नहीं हैं। मैंने इस प्रश्न को दूसरे में फंसाया: http://stackoverflow.com/questions/3469904/ – Wolkenjaeger

+0

आप शायद एंड्रॉइडप्लोरर v.3 पर एक नज़र डालना चाहते हैं। यह 7z सहित कई फ़ाइल प्रारूपों का समर्थन करता है। – Yongki

उत्तर

2

जाओ here:

LZMA एसडीके सिर्फ एनकोडर और एन्कोडिंग के लिए डिकोडर/कच्चे डेटा डिकोडिंग प्रदान करता है, लेकिन 7z संग्रह के भंडारण के लिए एक जटिल स्वरूप है एकाधिक फाइलें

-1

मुझे यह page मिला जो एक विकल्प प्रदान करता है जो एक आकर्षण की तरह काम करता है। आपको केवल compile 'org.apache.commons:commons-compress:1.8'

अपनी बिल्ड ग्रेबल स्क्रिप्ट में जोड़ना होगा और अपनी इच्छित सुविधा का उपयोग करना होगा। इस मुद्दे के लिए मैंने निम्नलिखित किया:

AssetManager am = getAssets(); 
     InputStream inputStream = null; 
     try { 
      inputStream = am.open("a7ZipedFile.7z"); 
      File file1 = createFileFromInputStream(inputStream); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
SevenZFile sevenZFile = null; 
     try{ 
      File f = new File(this.getFilesDir(), "a7ZipedFile.7z"); 
      OutputStream outputStream = new FileOutputStream(f); 
      byte buffer[] = new byte[1024]; 
      int length = 0; 
      while((length=inputStream.read(buffer)) > 0) { 
       outputStream.write(buffer,0,length); 
      } 

      try { 
       sevenZFile = new SevenZFile(f); 
       SevenZArchiveEntry entry = sevenZFile.getNextEntry(); 
       while (entry != null) { 
        System.out.println(entry.getName()); 
        FileOutputStream out = openFileOutput(entry.getName(), Context.MODE_PRIVATE); 
        byte[] content = new byte[(int) entry.getSize()]; 
        sevenZFile.read(content, 0, content.length); 
        out.write(content); 
        out.close(); 
        entry = sevenZFile.getNextEntry(); 
       } 
       sevenZFile.close(); 
       outputStream.close(); 
       inputStream.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     }catch (IOException e) { 
      //Logging exception 
      e.printStackTrace(); 
     } 

आयातित लाइब्रेरी के लिए केवल एक ही ड्रा वापस 200k है। इसके अलावा इसका उपयोग करना वास्तव में आसान है।

संबंधित मुद्दे