java压缩文件方法
来源:互联网 发布:html 图片存进数据库 编辑:程序博客网 时间:2024/05/18 17:39
/** * 压缩文件 * @param srcfile File[] 需要压缩的文件列表 * @param zipfile File 压缩后的文件 */public static void ZipFiles(java.io.File[] srcfile, java.io.File zipfile) { byte[] buf = new byte[1024]; try { // Create the ZIP file ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile)); //ZipOutputStream out = new ZipOutputStream(Response.getOutputStream());--设置成这样可以不用保存在本地,再输出, 通过response流输出。 // Compress the files for (int i = 0; i < srcfile.length; i++) { FileInputStream in = new FileInputStream(srcfile[i]); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(srcfile[i].getName())); // Transfer bytes from the file to the ZIP file int len; while ( (len = in.read(buf)) > 0) { out.write(buf, 0, len); } // Complete the entry out.closeEntry(); in.close(); } // Complete the ZIP file out.close(); System.out.println("压缩完成."); }catch (IOException e) { e.printStackTrace(); }}
0 0
- java压缩文件方法
- java压缩文件方法讨论
- Java压缩文件和解压缩文件
- java实现 zip压缩文件 三种方法
- java 压缩文件
- java压缩文件
- java压缩文件
- java 压缩文件
- java 压缩文件
- JAVA压缩文件
- java压缩文件
- JAVA 压缩文件
- java压缩文件
- java 压缩文件
- java压缩文件
- java 压缩文件
- java压缩文件
- Java压缩文件
- Android通知之状态栏通知
- 在数据库中使用关键字作为字段名
- /etc/passwd & /etc/shadow 详解
- Spring2.5注解不需要接口注入的方法
- js中apply方法的使用
- java压缩文件方法
- 新建用户并添加到管理组
- cocos2dx输出Log的几种方法
- android 手电筒 代码
- C#设置当前程序通过IE代理服务器上网
- PHP中通过socket实现聊天功能
- 经典问题总结(三)
- 01背包 HDU2602
- android中的Handler