Java???Gzip
???????????? ???????[ 2014/12/18 11:25:25 ] ????????Java ??????? ????
????gzip??????????????????????????к????????????Ч??.??sun?????????jdk?а?????java.util.zip??????gzip??????????.???java???????????????gzip?????????.?????????????????????????.
????(???:gzip.java)
import java.io.*;
import java.util.zip.*;
public class gzip
{
public static void main(String[] args)
{
if (args.length !=2)
{
System.out.println("Usage:java gzip ");
System.exit(1);
}
try
{
//??????????????????????
FileInputStream fin=new FileInputStream(args[0]);
//???????????????
FileOutputStream fout=new FileOutputStream(args[1]);
//????gzip????????
GZIPOutputStream gzout=new GZIPOutputStream(fout);
byte[] buf=new byte[1024];//?趨???????????
int num;
while ((num=fin.read(buf)) != -1)
{
gzout.write(buf??0??num);
}
gzout.close();//!!!??????????????????????????.????????????????????????.
fout.close();
fin.close();
}catch(IOException e)
{
System.out.println(e);
}
}
}
(?????:unzip.java)
import java.io.*;
import java.util.zip.*;
public class ungzip
{
public static void main(String[] args)
{
if (args.length !=2)
{
System.out.println("Usage:java ungzip ");
System.exit(1);
}
try
{
//????gzip????????????
FileInputStream fin=new FileInputStream(args[0]);
//????gzip?????????
GZIPInputStream gzin=new GZIPInputStream(fin);
//???????????????
FileOutputStream fout=new FileOutputStream(args[1]);
byte[] buf=new byte[1024];
int num;
while ((num=gzin.read(buf??0??buf.length)) != -1)
{
fout.write(buf??0??num);
}
gzin.close();
fout.close();
fin.close();
}catch(IOException e)
{
System.out.println(e);
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11