【文件属性】:
文件名称:java ZIP 解压缩
文件大小:2KB
文件格式:ZIP
更新时间:2018-03-29 10:07:24
java 解压缩
java语言操作解压缩文件。
/**
* 数据压缩
*
* @param data
* @return
* @throws Exception
*/
public static byte[] compress(byte[] data) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// 压缩
compress(bais, baos);
byte[] output = baos.toByteArray();
baos.flush();
baos.close();
bais.close();
return output;
}
/**
* 文件压缩
*
* @param file
* @throws Exception
*/
public static void compress(File file) throws Exception {
compress(file, true);
}
【文件预览】:
GZipUtilsTest.java
GZipUtils.java