ZipOutputStream输出流

xiaoxiao2021-02-28  88

转自:http://blog.csdn.net/z69183787/article/details/8290811

public static void zip(File zf, File[] sf) {//sf 需要压缩的所有文件,zf 输出的压缩包的文件路径 byte[] buf = new byte[1024]; try { FileOutputStream fos = new FileOutputStream(zf); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(fos)); for (int i = 0; i < sf.length; i++) { FileInputStream in = new FileInputStream(sf[i]); out.putNextEntry(new ZipEntry("" + sf[i].getName()));//把所有文件压缩到一个压缩包里面 int len; if(in.available() > 0){ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } out.closeEntry(); in.close(); } out.close(); } catch (IOException e) { e.printStackTrace(); } }

转载请注明原文地址: https://www.6miu.com/read-32047.html

最新回复(0)