/**
* 生成.zip文件;
* @param path
* @throws IOException
*/
public static InputStream craeteZipPath(String path) throws IOException{
ZipOutputStream zipOutputStream = null;
String lj=path+"\\工单信息表.zip";
File file = new File(lj);
zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
File[] files = new File(path).listFiles();
FileInputStream fileInputStream = null;
byte[] buf = new byte[1024];
int len = 0;
if(files!=null && files.length > 0){
for(File excelFile:files){
String fileName = excelFile.getName();
fileInputStream = new FileInputStream(excelFile);
//放入压缩zip包中;
zipOutputStream.putNextEntry(new ZipEntry(path + "/"+fileName));
//读取文件;
while((len=fileInputStream.read(buf)) >0){
zipOutputStream.write(buf, 0, len);
}
//关闭;
zipOutputStream.closeEntry();
if(fileInputStream != null){
fileInputStream.close();
}
}
}
if(zipOutputStream !=null){
zipOutputStream.close();
}
File f = new File(lj);
InputStream istream = new FileInputStream(f);
return istream;
}
转自:
点击打开链接
生成.zip文件
最新推荐文章于 2023-10-08 18:02:13 发布