import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Yasuo {
//压缩文件程序
public static void main(String[] args) throws Exception{
String path = "E:\\my.txt";
String zip = "E:\\压缩";
File file = new File(path);
File zip1 = new File(zip + "one.zip");
InputStream tem =new FileInputStream(file);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip1));
out.putNextEntry(new ZipEntry("newzipone.txt"));
out.setComment("i am lucky");
int a = 0;
while ((a =tem.read()) != -1 ){
out.write(a);
}
tem.close();
out.close();
}
}
使用程序压缩文件