8 Ağustos 2012 Çarşamba

Android de unzip yapabilen method.

private boolean unpackZip() {
    InputStream is;
    ZipInputStream zis;
    String path = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/downloadFolder"; //sdcard ta zip dosyasının bulunduğu klasör
    String fileName = "music" + ".zip"; //zip dosyasi ismi tanımlanacak
    path += "/";
    try {
        is = new FileInputStream(path+fileName);
        zis = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry ze;
       

        while ((ze = zis.getNextEntry()) != null) {
           
           
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int count;


            String filename = ze.getName();
            File tmpFile = File.createTempFile(filename, "tmp");
            tmpFile.deleteOnExit();
            FileOutputStream fout = new FileOutputStream(path + filename);


            while ((count = zis.read(buffer)) != -1) {
                baos.write(buffer, 0, count);
                byte[] bytes = baos.toByteArray();
                fout.write(bytes);
                baos.reset();
            }

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

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

    return true;
}

Hiç yorum yok:

Yorum Gönder