import java.util.zip.ZipOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.io.FileOutputStream;
import java.io.FileInputStream;
class CSVZip {
public static void Zip(String file,String zipfile) {
try {
//创建文件输入流对象
FileInputStream in = new FileInputStream(file); //0
//创建文件输出流对象
FileOutputStream out = new FileOutputStream(zipfile); //1
//创建ZIP数据输出流对象
ZipOutputStream zipOut = new ZipOutputStream(out);
//创建指向压缩原始文件的入口
ZipEntry entry = new ZipEntry(file); //0
zipOut.putNextEntry(entry);
//向压缩文件中输出数据
int nNumber;
byte[] buffer = new byte[512];
while ( (nNumber = in.read(buffer)) != -1)
zipOut.write(buffer, 0, nNumber);
//关闭创建的流对象
zipOut.close();
out.close();
in.close();
}catch (IOException e) {
System.out.println(e);
}
}
}