在解压缩Android应用程序在SD卡中的压缩文件解压缩、压缩文件、应用程序、Android

2023-09-12 00:17:40 作者:再贱不见。

我有压缩密码保护保存在SD卡上的Andr​​oid模拟器的视频文件。现在我想通过code解压到SD卡的视频文件。我怎样才能做到这一点?任何帮助或code? 在此先感谢

解决方案

 进口android.util.Log;
进口的java.io.File;
进口java.io.FileInputStream中;
进口java.io.FileOutputStream中;
进口java.util.zip.ZipEntry中;
进口java.util.zip.ZipInputStream中;

/ **
 *
 * @author乔恩
 * /
公共类DECOM preSS {
  私人字符串_zipFile;
  私人字符串_location;

  公共DECOM preSS(字符串的压缩文件,字符串位置){
    _zipFile = zip文件;
    _location =位置;

    _dirChecker();
  }

  公共无效解压缩(){
    尝试  {
      的FileInputStream鳍=新的FileInputStream(_zipFile);
      ZipInputStream ZIN =新ZipInputStream(翅);
      ZipEntry的泽= NULL;
      而((泽= zin.getNextEntry())!= NULL){
        Log.v(DECOM preSS的,解压缩+ ze.getName());

        如果(ze.isDirectory()){
          _dirChecker(ze.getName());
        } 其他 {
          FileOutputStream中FOUT =新的FileOutputStream(_location + ze.getName());
          对于(INT C = zin.read(); C = -1;!C = zin.read()){
            fout.write(C);
          }

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

      }
      zin.close();
    }赶上(例外五){
      Log.e(DECOM preSS,解压,E);
    }

  }

  私人无效_dirChecker(字符串DIR){
    文件F =新的文件(_location +方向);

    如果(!f.isDirectory()){
      f.mkdirs();
    }
  }
}
 

在你的情况::

 字符串zipFilename = Environment.getExternalStorageDirectory()+/files.zip;
字符串unzipLocation = Environment.getExternalStorageDirectory()+/解压缩/;

DECOM preSS D =新DECOM preSS(zipFilename,unzipLocation);
d.unzip();
 

RAR文件解压

I have a zipped password protected a video file saved on sd card on android emulator. Now i want to unzip that video file on sd card through code. How can i achieve that? Any help or code? Thanks in advance

解决方案

import android.util.Log; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.util.zip.ZipEntry; 
import java.util.zip.ZipInputStream; 

/** 
 * 
 * @author jon 
 */ 
public class Decompress { 
  private String _zipFile; 
  private String _location; 

  public Decompress(String zipFile, String location) { 
    _zipFile = zipFile; 
    _location = location; 

    _dirChecker(""); 
  } 

  public void unzip() { 
    try  { 
      FileInputStream fin = new FileInputStream(_zipFile); 
      ZipInputStream zin = new ZipInputStream(fin); 
      ZipEntry ze = null; 
      while ((ze = zin.getNextEntry()) != null) { 
        Log.v("Decompress", "Unzipping " + ze.getName()); 

        if(ze.isDirectory()) { 
          _dirChecker(ze.getName()); 
        } else { 
          FileOutputStream fout = new FileOutputStream(_location + ze.getName()); 
          for (int c = zin.read(); c != -1; c = zin.read()) { 
            fout.write(c); 
          } 

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

      } 
      zin.close(); 
    } catch(Exception e) { 
      Log.e("Decompress", "unzip", e); 
    } 

  } 

  private void _dirChecker(String dir) { 
    File f = new File(_location + dir); 

    if(!f.isDirectory()) { 
      f.mkdirs(); 
    } 
  } 
} 

In your case::

String zipFilename = Environment.getExternalStorageDirectory() + "/files.zip"; 
String unzipLocation = Environment.getExternalStorageDirectory() + "/unzipped/"; 

Decompress d = new Decompress(zipFilename, unzipLocation); 
d.unzip(); 

 
精彩推荐
图片推荐