android zip怎么压缩,android自带zip轻松实现压缩解压
android自带zip轻松实现压缩解压
开发过程用到了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
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
