但见新人笑,哪闻旧人哭,杜甫的诗句很好的诠释了现在 IT 和互联网行业对待技术的态度,区块链、AI、大数据、AR/VR 等新技术层出不穷,每个人都在追逐 The Next Thing。在这个被摩尔定律决定的行业,平均每 18 个月就能让计算能力翻倍,让技术井喷。但是过快的发展速度一定程度上也给新的技术带了不稳定性,就像 Gerald Weinberg 说的那样:
https://developer.ibm.com/mainframe/products/zosconnect/ https://developer.ibm.com/mainframe/category/zos-connect
FileInputStream fis = null; BufferedInputStream bis = null; FileOutputStream fos = null; ZipOutputStream zos " + sourceFilePath + "里面不存在文件,无需压缩."); }else{ fos = new FileOutputStream(zipFile); zos //创建ZIP实体,并添加进压缩包 ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName()); zos.putNextEntry = -1){ zos.write(bufs,0,read); } } flag = true; } } } catch (FileNotFoundException = zos) zos.close(); if(null != fis) fis.close(); if(null !
= null; try { fos = new FileOutputStream(target); zos = new BufferedOutputStream(fos)); // 添加对应的文件Entry addEntry("/", source, zos @param base * 基路径 * * @param source * 源文件 * @param zos throws IOException */ private static void addEntry(String base, File source, ZipOutputStream zos = -1) { zos.write(buffer, 0, read); } zos.closeEntry
files * 多个文件 * @param baseFolder * 压缩到ZIP的父级目录(目录后面跟上File.separator) * @param zos * @throws Exception */ private static void zip(File[] files, String baseFolder, ZipOutputStream zos )) { // 递归 zip(file.listFiles(), baseFolder + file.getName() + File.separator, zos } entry = new ZipEntry(baseFolder + file.getName()); // 加入 zos.putNextEntry = -1) { // 写入 zos.write(buffer, 0, count); } zos.closeEntry()
= null ; try { zos = new ZipOutputStream(out); File sourceFile = new = null){ try { zos.close(); } catch (IOException ) { byte[] buf = new byte[BUFFER_SIZE]; zos.putNextEntry(new ZipEntry = -1){ zos.write(buf, 0, len); } zos.closeEntry() = null){ try { zos.close(); } catch (IOException
); compress(sourceFile, zos, sourceFile.getName()); var end = System.currentTimeMillis +" ms"); } catch (e) { throw ("zip error from ZipUtils"+e); } finally { if(zos = null){ try { zos.close(); } catch (e) { log (sourceFile)){ zos.putNextEntry(new ZipEntry(name)); var len; var = -1){ zos.write(len); } zos.closeEntry(); put.close
ByteArrayOutputStream bos = new ByteArrayOutputStream(); DeflaterOutputStream zos = new DeflaterOutputStream(bos); zos.write(data.getBytes()); zos.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); InflaterOutputStream zos = new InflaterOutputStream(bos); zos.write(decodeBASE64(encodeData)); zos.close
(buffer, 0, len) len = fis.read(buffer) } 不要忘了关闭条目和流: zos.flush() zos.closeEntry() fis.close() zos.close (buffer, 0, len) len = fis.read(buffer) } zos.flush() zos.closeEntry() fis.close () } zos.close() 对于每个文件都需要添加一个条目,然后写入内容,最后别忘了关闭条目。 (buffer, 0, len) len = fis.read(buffer) } zos.flush() zos.closeEntry ", src, zos) zos.close() 这样就可以将一个文件夹下的所有文件打包进压缩包里了。
2、压缩文件注释的中文乱码问题:zos.setComment("中文测试");通过使用设置编码的方法(zos.setEncoding("gbk");)发现问题,测试项目的编码方式为gbk,而默认编码是utf String[] args) throws Exception { File f = new File("中文测试.txt"); ZipOutputStream zos (new BufferedOutputStream( new FileOutputStream("zipTest.zip"), 1024)); zos.putNextEntry = -1) { zos.write(c); } zos.setEncoding("gbk"); zos.setComment ("中文测试"); zos.closeEntry(); zos.close(); } } 谢谢大家,希望帮助更多的人
= new ZipOutputStream(fos); zos.putNextEntry(new ZipEntry(file.getName())); byte[] bytes = Files.readAllBytes(Paths.get(filePath)); zos.write(bytes, 0, bytes.length) ; zos.closeEntry(); zos.close(); } catch (FileNotFoundException ex) FileOutputStream fos = new FileOutputStream(zipFileName); ZipOutputStream zos (bytes, 0, bytes.length); zos.closeEntry(); } zos.close();
= null; try { zos = new ZipOutputStream(out); File sourceFile = new File(srcDir { throw new RuntimeException("zip error from ZipUtils", e); } finally { if (zos 会压缩失败) * @throws Exception */ private static void compress(File sourceFile, ZipOutputStream zos = -1) { zos.write(buf, 0, len); } // Complete the entry zos.closeEntry // 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了 compress(file, zos
{ if (zos ! = null) { zos.finish(); CloseUtils.closeIO(zos); } return zipFile(resFile, "", zos, comment); } finally { if (zos ! = null) { CloseUtils.closeIO(zos); } } } /** * 压缩文件 = -1) { zos.write(buffer, 0, len); } zos.closeEntry
home/liangruihua/ziptest/1.zip -- the out put file path and // name ZipOutputStream zos home/liangruihua/ziptest/1.zip" ) ) ; BufferedOutputStream bos = new BufferedOutputStream ( zos ) ; // set the file name in the .zip file zos.putNextEntry ( new ZipEntry ( "1.txt" ) ) ; // set the declear zos.setComment ( "by liangruihua test!" compress File file = new File ( "/home/liangruihua/ziptest/test" ) ; ZipOutputStream zos
BufferedInputStream bis = null; FileOutputStream fos = null; ZipOutputStream zos } else { fos = new FileOutputStream(zipFile); zos ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName()); zos.putNextEntry = -1) { zos.write(bufs, 0, read); } = zos) { zos.close(); } } catch (IOException
FileInputStream fis = null; BufferedInputStream bis = null; FileOutputStream fos = null; ZipOutputStream zos + sourceFilePath + "里面不存在文件,无需压缩."); } else { fos = new FileOutputStream(zipFile); zos // 创建ZIP实体,并添加进压缩包 ZipEntry zipEntry = new ZipEntry(sourceFiles[i].getName()); zos.putNextEntry = -1) { zos.write(bufs, 0, read); } } flag = true; } } } catch = zos) zos.close(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException
"" : "等" + sourcePath.length + "个文件") + ".zip"; ZipOutputStream zos = null; try { zos ); } } finally { if (zos ! = null) { zos.close(); } } return zipName; } 2)FileService中定义writeZos */ private void writeZos(File file, String basePath, ZipOutputStream zos) throws IOException { = -1) { zos.write(data, 0, count); } bis.close(); } } 3)当成功下载
ZipExample { public static void main(String[] args) throws IOException { try (ZipOutputStream zos FileOutputStream("archive.zip"))) { ZipEntry entry = new ZipEntry("hello.txt"); zos.putNextEntry (entry); byte[] data = "这是文件内容".getBytes(); zos.write(data); zos.closeEntry String archiveName = "log_" + System.currentTimeMillis() + ".zip"; try (ZipOutputStream zos (entry); Files.copy(Paths.get(logFile), zos); zos.closeEntry(); }
= null; OutputStream os = response.getOutputStream(); try { zos = new ZipOutputStream = null) { zos.putNextEntry(new ZipEntry(imagePath)); int len; ();//不让一个循环后ftpClient自动关闭 } } zos.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (zos ! = null) { try { zos.close(); } catch (IOException
= ZipOutputStream(cos) // 压缩文件 compress(dir, zos, "") zos.flush() zos.close() } private fun compress(srcFile: File, zos: ZipOutputStream, basePath: String) { if (srcFile.isDirectory) { , basePath + srcFile.name + "/") } } else { compressFile(srcFile, zos, basePath) } } private fun compressFile(file: File, zos: ZipOutputStream, dir: String) { // 拼接完整的文件路径名称 = -1) { zos.write(data, 0, len) } fis.close() zos.closeEntry() } 六、执行结果 ---- 下图中