gz 解压缩后比原文件大很多
原文件 index.xml 只有300KB,使用java生成压缩文件index.xml.gz 文件大小为25KB. 但是再次解压出来的index.xml 竟然有8M.而且用notpad++ 打开已经全是乱码了.求解!附上生成gz文件的java代码:
public static void compressFile(String inFileName) {
String outFileName = inFileName + ".gz";
FileInputStream in = null;
try {
in = new FileInputStream(inFileName);
}catch (FileNotFoundException e) {
e.printStackTrace();
}
GZIPOutputStream out = null;
try {
out = new GZIPOutputStream(new FileOutputStream(outFileName));
}catch (IOException e) {
e.printStackTrace();
}
byte[] buf = new byte[1024];
int len = 0;
try {
while ((len = in.read()) > 0) {
out.write(buf, 0, len);
}
in.close();
System.out.println("Completing the GZIP file..."+outFileName);
out.flush();
out.close();
}catch (IOException e) {
e.printStackTrace();
}
}
如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

发布评论
需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。