Java实现打包文件
2020-12-13 03:40
标签:输入流 next zip write str while ext 压缩 row 把文件打包到压缩包里 Java实现打包文件 标签:输入流 next zip write str while ext 压缩 row 原文地址:https://www.cnblogs.com/LixiaoFeng1650062546/p/11083598.htmlpublic void zip (String... files) throws IOException {
//创建文件打包流对象
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("d:\\eee.zip"));
for (String file : files) {
//内容描述
ZipEntry zipEntry = new ZipEntry(file);
zos.putNextEntry(zipEntry);
//创建文件输入流
FileInputStream fis = new FileInputStream(file);
int c;
while ((c = fis.read()) > 0) {
zos.write(c);
}
fis.close();
}
zos.close();
}