SORU
1 AĞUSTOS 2010, Pazar


Nasıl sıkıştırılmış dosyaları Android program aracılığıyla?

Verilen birkaç dosyaları unzips küçük bir kod parçası lazım .zip dosyası ve sıkıştırılmış dosya içinde olduklarını biçimine göre ayrı dosyaları verir. Bilginiz post ve bana yardım et lütfen.

CEVAP
12 HAZİRAN 2012, Salı


Peno versiyonu biraz optimize edilmiş oldu. Performans artışı hissedilir.

private boolean unpackZip(String path, String zipname)
{       
     InputStream is;
     ZipInputStream zis;
     try 
     {
         String filename;
         is = new FileInputStream(path   zipname);
         zis = new ZipInputStream(new BufferedInputStream(is));          
         ZipEntry ze;
         byte[] buffer = new byte[1024];
         int count;

         while ((ze = zis.getNextEntry()) != null) 
         {
             // zapis do souboru
             filename = ze.getName();

             // Need to create directories if not exists, or
             // it will generate an Exception...
             if (ze.isDirectory()) {
                File fmd = new File(path   filename);
                fmd.mkdirs();
                continue;
             }

             FileOutputStream fout = new FileOutputStream(path   filename);

             // cteni zipu a zapis
             while ((count = zis.read(buffer)) != -1) 
             {
                 fout.write(buffer, 0, count);             
             }

             fout.close();               
             zis.closeEntry();
         }

         zis.close();
     } 
     catch(IOException e)
     {
         e.printStackTrace();
         return false;
     }

    return true;
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • GFX Tutorials

    GFX Tutorial

    12 AĞUSTOS 2013
  • iNCH

    iNCH

    20 Temmuz 2009
  • Sarah's YouTube Channel

    Sarah's YouT

    27 Temmuz 2009