/**
* 从zip文件中,读取指定的压缩内容
* @param zipFile zip压缩文件
* @param fileName 需要读取的文件名
* @param outTxtFile 输出文件
*/
private static void readFileFromZipEntry(File zipFile, String fileName, File outTxtFile) {
try (ZipInputStream zipIs = new ZipInputStream(Files.newInputStream(zipFile.toPath()),
Charset.forName("GBK")); FileOutputStream fw = new FileOutputStream(outTxtFile)) {
ZipEntry zipEntry = null;
while ((zipEntry = zipIs.getNextEntry()) != null) {
if (zipEntry.getName().contains(fileName)) {
byte[] bytes = new byte[1024];
int len = -1;
while ((len = zipIs.read(bytes, 0, bytes.length)) != -1) {
fw.write(bytes,0,len);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
标签:Java,读取,ZipEntry,bytes,param,new,outTxtFile
From: https://www.cnblogs.com/hard-won/p/17417548.html