android自带zip轻松实现压缩解压
来源:互联网 发布:mac怎么找到安装目录 编辑:程序博客网 时间:2024/05/29 17:46
开发过程用到了zip压缩包,写了一个工具类,该类可以实现把字符串直接压缩成zip格式,省去了写入文件再压缩的步骤:
/** * * @author shx * 压缩和解压缩工具 * */public class ZipUtil {/** * 压缩方法 * @param str 要压缩的字符串 * @param path路径 * @throws IOException */public static void compress(String str,String path) throws IOException {if (null == str || str.length() <= 0) {return;}FileOutputStream fileOutputStream = new FileOutputStream(path);GZIPOutputStream gzip = new GZIPOutputStream(fileOutputStream);gzip.write(str.getBytes("utf-8"));gzip.close( );fileOutputStream.close();}/** * 解压缩 * @param context * @param path * @return */public static String unCompress(Context context,String path) {try {File file = new File(path);if (!file.exists()) {return context.getResources().getString(R.string.FileNotExits);}ByteArrayOutputStream out = new ByteArrayOutputStream();// 创建一个新的输出流FileInputStream fileInputStream = new FileInputStream(path);GZIPInputStream gzip = new GZIPInputStream(fileInputStream);byte[] buffer = new byte[256];int n = 0;// 将未压缩数据读入字节数组while ((n = gzip.read(buffer)) >= 0) {out.write(buffer, 0, n);}return out.toString("utf-8");} catch (Exception e) {e.printStackTrace();}return null;}
2 0
- android自带zip轻松实现压缩解压
- 实现zip压缩解压
- java实现zip压缩、解压
- Android 压缩解压zip文件
- Android 压缩解压zip文件
- Android 压缩解压zip文件
- Android 压缩解压zip文件
- Android 压缩解压zip文件
- android -解压和压缩zip
- 支持中文的zip压缩和解压,修改自带jdk ZipInputStream、ZipOutputStream、ZipEntry代码
- android实现zip解压
- php 自带的解压zip函数
- php 自带压缩zip函数
- windows系统自带压缩解压命令
- .NET 自带的压缩和解压
- .Net 实现 Zip 压缩和解压
- java实现zip文件压缩,解压
- java实现zip压缩及解压
- Cocos2d-x 3.0 开发(四)使用CocoStudio创建UI并载入到程序中
- Codeforces Round #245 (Div. 1)B 递推DP
- 继承于CCObject而非CCLayer的界面的显示
- 【LeetCode with Python】 Remove Duplicates from Sorted Array II
- WPF/Silverlight深度解决方案:(二)Silverlight源码之自我保护(加密)
- android自带zip轻松实现压缩解压
- 7.27派生类的析构函数
- POJ3083 Children of the Candy Corn(BFS+DFS水题)
- NYOJ-开灯问题
- hdu 1495(bfs)
- 7.27多重继承派生类的构造函数
- Cocos2d-x 3.0开发(三)点击交互的四种处理
- 7.28基类对象的指针指向公用派生类对象的应用。
- 7.28组合