java 生成Zip文件

来源:互联网 发布:淘宝老客户维护方案 编辑:程序博客网 时间:2024/05/22 00:50
//读取需要压缩文件  也可以修改成f:/sql.txtFile souceFile = new File("D:\\sql.txt") ;//生成写入压缩文件ZipOutputStream out = new ZipOutputStream(new FileOutputStream("D:\\outfile.zip"));out.putNextEntry(new ZipEntry(souceFile.getName()));FileInputStream in = new FileInputStream(souceFile);int b;byte[] by = new byte[1024];while ((b = in.read(by)) != -1){//将需要压缩文件数据写到压缩文件中out.write(by, 0, b);}in.close();out.close() ;
0 0