多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > android自帶zip輕松實現壓縮解壓

android自帶zip輕松實現壓縮解壓

來源:程序員人生   發布時間:2014-09-06 21:29:40 閱讀次數:5564次

開發過程用到了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; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 一级毛片ab片高清毛片 | 黄xxxx| xxxxx性欧美hd另类 | 日本乱人伦片中文三区 | 精品国产免费第一区二区三区日韩 | jizz日本视频 | 男人午夜天堂 | 1000部精品久久久久久久久 | 在线看黄网址 | 一级毛片aa | 美国人成毛片在线播放 | 国产欧美综合在线 | 国产亚洲精品激情一区二区三区 | 日日摸人人拍人人澡 | 亚洲国产日韩欧美综合久久 | 亚洲欧美精品天堂久久综合一区 | аⅴ成人天堂中文在线 | 羞羞视频入口网站 | 国产精品欧美亚洲 | 亚洲欧美专区精品伊人久久 | 激情综合色综合久久综合 | 依人久久 | 亚洲色图色 | 国产国语一级a毛片高清视频 | a天堂影院 | 久久精品国产精品亚洲20 | 在线观看操 | 一区二区国产精品 | 性欧美性 | 国产欧美成人不卡视频 | 韩国三级做爰中文字幕 | 91精品日韩 | www国产精品com | 性生活国产 | 激情区小说区偷拍区图片区 | 亚洲天堂在线视频观看 | 视频在线国产 | 欧美jizzhd精品欧美巨大 | 天堂网在线网站成人午夜网站 | 欧美精品在线免费 | 色聚网 |