1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > java 文件打包zip_java 多个文件打包zip

java 文件打包zip_java 多个文件打包zip

时间:2022-08-15 16:28:13

相关推荐

java 文件打包zip_java 多个文件打包zip

/**

* 多个文件打包成zip

*/

public class ZipDemo

{

private static void create() throws Exception{

String path="d:/demo.zip";

ZipOutputStream zipOut=new ZipOutputStream(new FileOutputStream(new File(path)));

File[] files={new File("d:/1.doc"),new File("d:/2.doc")};

byte [] buffer=new byte[1024];

int len=-1;

for(int i=0;i

FileInputStream in=new FileInputStream(files[i]);

zipOut.putNextEntry(new ZipEntry(files[i].getName()));

while((len=in.read(buffer))!=-1){

zipOut.write(buffer, 0, len);

}

zipOut.closeEntry();

in.close();

}

zipOut.close();

System.out.println("文件已经压缩成zip了"+path);

}

public static void main(String[] args) throws Exception

{

create();

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。