Apache jar 包下载


/** *  */package com.ztb.sebook.utils;import java.io.DataInputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import org.apache.commons.compress.archivers.ArchiveEntry;import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;import org.apache.commons.compress.archivers.zip.ZipFile;import com.ztb.sebook.activitys.R;import android.content.Context;import android.content.res.AssetFileDescriptor;import android.content.res.Resources;/** *  *  * @author zhao.tb */public class FileUtils {/** * unZip * UnZip the *****.zip in Assets folder. *  * @param c * @param zipFile * <br> Just the Name * @param outFilePath * <br> eg.Environment.getExternalStorageDirectory().getAbsolutePath() + "/ebook/data/"; * @return */public static boolean unZip(Context c,String zipFileName, String outFilePath) {boolean flag = false;try {//ZipFile zf = new ZipFile(zipFile, "GBK"); // 此处设置编码格式 支持中文文件名解压ZipArchiveInputStream zin = new ZipArchiveInputStream(c.getAssets().open(zipFileName), "GBK", true);ArchiveEntry entry = zin.getNextEntry();byte[] buf = new byte[409600];FileOutputStream out;while (entry != null) {if (entry.isDirectory()) {File newDir = new File(outFilePath + entry.getName());newDir.mkdir();} else {String name = entry.getName();File outputFile = new File(outFilePath + name);String outputPath = outputFile.getCanonicalPath();name = outputPath.substring(outputPath.lastIndexOf("/") + 1);outputPath = outputPath.substring(0, outputPath.lastIndexOf("/"));File outputDir = new File(outputPath);outputDir.mkdirs();outputFile = new File(outputPath, name);outputFile.createNewFile();out = new FileOutputStream(outputFile);int numread = 0;do {numread = zin.read(buf);if (numread <= 0) {break;} else {out.write(buf, 0, numread);}} while (true);out.close();}entry = zin.getNextEntry();}flag = true;} catch (Exception e) {e.printStackTrace();}return flag;}/** * unZip * UnZip file in Raw folder. * @param c * @param rawId * @param outPath * <br>eg.Environment.getExternalStorageDirectory().getAbsolutePath() + "/ebook/data/"; * @return */public static boolean unZip(Context c, int rawId, String outPath) {FileOutputStream out;byte buf[] = new byte[102400];try {Resources res = c.getResources();AssetFileDescriptor fd = res.openRawResourceFd(rawId);InputStream stream = fd.createInputStream();ZipInputStream zis = new ZipInputStream(stream);ZipEntry entry = zis.getNextEntry();while (entry != null) {if (entry.isDirectory()) {File newDir = new File(outPath + entry.getName());newDir.mkdir();} else {String name = entry.getName();File outputFile = new File(outPath + name);String outputPath = outputFile.getCanonicalPath();name = outputPath.substring(outputPath.lastIndexOf("/") + 1);outputPath = outputPath.substring(0, outputPath.lastIndexOf("/"));File outputDir = new File(outputPath);outputDir.mkdirs();outputFile = new File(outputPath, name);outputFile.createNewFile();out = new FileOutputStream(outputFile);int numread = 0;do {numread = zis.read(buf);if (numread <= 0) {break;} else {out.write(buf, 0, numread);}} while (true);out.close();}entry = zis.getNextEntry();}return true;} catch (IOException e) {e.printStackTrace();return false;}}}


更多相关文章

  1. http通信,Android(安卓)Gzip压缩解压
  2. Android倒计时控件 CountdownView
  3. 通过SOCKET实现文件下载
  4. Android(安卓)中英文切换工具类
  5. Android中关于路径
  6. Volley框架网络访问String,JsonObject,JsonArray
  7. Android(安卓)Java 与 C++ 调用过程中的常量,路径名、文件名、后
  8. Android(安卓)zip文件压缩解压缩
  9. android 从Assets中读取中文文本

随机推荐

  1. VLC for Android(安卓)on Linux
  2. Android实现点击切换视图并跳转传值
  3. Where To Start - Learning Android(安卓
  4. 使用webview打开浏览器
  5. 弹出式菜单PopMenu
  6. Ubuntu16.04上Android(安卓)N开发环境配
  7. Android(安卓)在自定义view中动态设置布
  8. WebView的使用
  9. Android学习笔记之Gallery(2)
  10. android:圆形 ImageView