//读取需要压缩文件 也可以修改成f:/sql.txt File 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() ;
怎样用Java生成ZIP文件
最新推荐文章于 2022-09-15 15:28:05 发布