JAVA 压缩文件
程序员文章站
2022-03-03 09:06:05
...
import java.io.*;
import java.util.zip.*;
public class raintime{
public static void main(String[] args){
try{
BufferedReader in=new BufferedReader(
new InputStreamReader(new FileInputStream(args[0]),"ISO8859_1"));
FileOutputStream f=new FileOutputStream(args[0]+".zip");
CheckedOutputStream ch=new CheckedOutputStream(f,new CRC32());
ZipOutputStream out=new ZipOutputStream(
new BufferedOutputStream(ch));
int c;
out.putNextEntry(new ZipEntry(args[0]));
while((c=in.read())!=-1)
out.write(c);
in.close();
out.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
测试通过,运行正常!
cmd:>java raintime SoftwarePath;