我正在从X站点下载所有gz格式的文件。在将所有文件下载到临时文件夹后,当我精确到0KB。。请帮我写代码注释。。代码的任何更改
URL site = new URL (sb.toString());
URLConnection uc = site.openConnection();
uc.setRequestProperty("Accept-Encoding", "gzip");//Here the change
java.io.BufferedInputStream in = new BufferedInputStream(uc.getInputStream());
//ZipInputStream gzin = new ZipInputStream(in);
GZIPInputStream gzin = new GZIPInputStream(in);
fileName = fileName.substring(fileName.lastIndexOf("/")+1);
File destFile = new File("D:\source\"+fileName);
java.io.FileOutputStream fos = new FileOutputStream(destFile);
GZIPOutputStream gz = new GZIPOutputStream(fos);
byte data[] = new byte[65536];
int gsize = 0;
while((gsize = gzin.read(data)) != -1)
{
gz.write(data, 0, gsize);
}
添加
gz.close();
最后。
此外,如果你马上要再次压缩某个东西,那么解压缩它是没有意义的。如果您真的想保存压缩版本,请从代码中删除GZipInputStream和GZipOutputStream,因为这是您当前正在做的事情。