`
refar
  • 浏览: 13083 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

ZIP压缩单文件

F# 
阅读更多

public static boolean zipFile(String file) {
		boolean succ = false;
		int BUFFER = 2048;
		try {
			BufferedInputStream origin = null;
			FileOutputStream dest = new FileOutputStream(file.substring(0, file.lastIndexOf(".")) + ".zip");
			ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
					dest));
			byte data[] = new byte[BUFFER];
			File f = new File(file);

			FileInputStream fi = new FileInputStream(f);
			origin = new BufferedInputStream(fi, BUFFER);
			ZipEntry entry = new ZipEntry(f.getName());
			out.putNextEntry(entry);
			int count;
			while ((count = origin.read(data, 0, BUFFER)) != -1) {
				out.write(data, 0, count);
			}
			origin.close();
			out.close();
			succ = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return succ;
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics