标签:关闭 extent NPU 中文 input 文件流 file byte pat
/** * 解压zip文件 * * TODO 压缩包内文件有中文会出错 * * @param zipFileStream zip文件流 * @param targetPath 解压路径 * @throws IOException */ public static void unZip(InputStream zipFileStream, String targetPath) throws IOException{ ZipInputStream zipInputStream = null; try { // 构造zipInputStream zipInputStream= new ZipInputStream(zipFileStream); ZipEntry zipEntry = zipInputStream.getNextEntry(); while(zipEntry != null){ // 如果目录 if (zipEntry.getName().endsWith("/") || zipEntry.getName().endsWith("\\")){ File dir = new File(targetPath + zipEntry.getName().substring(0,zipEntry.getName().length()-1)); if (!dir.exists()){ dir.mkdirs(); } }else { // 是文件 File tmp = new File(targetPath+zipEntry.getName()); if (!tmp.exists()){ // 先判断父路径是否存在 tmp.getParentFile().mkdirs(); // 输出流生成新文件 OutputStream outputStream = new FileOutputStream(tmp); byte[] buf = new byte[102400]; int n=0; while((n=zipInputStream.read(buf))!= -1){ outputStream.write(buf, 0, n); outputStream.flush(); } outputStream.close(); } } zipInputStream.closeEntry(); zipEntry = zipInputStream.getNextEntry(); } } finally { // 关闭流 if (zipInputStream != null) { try { zipInputStream.close(); } catch (IOException e) { } } } }
标签:关闭 extent NPU 中文 input 文件流 file byte pat
原文地址:https://www.cnblogs.com/badboyh2o/p/11373716.html