有没有java压缩工具

发布于 2024-07-30 11:36:19 字数 298 浏览 5 评论 0 原文

我需要(解压缩)一些文件,经过一番谷歌搜索后,我没有找到任何实用程序来执行此操作。 我知道我可以使用内置的 java.uitl.zip.* 类来完成此操作,但没有任何实用程序可以使其更轻松,最好像这样:

SomeClass.unzip("file_name.zip", "target_directory") ;

SomeClass.zip("source_directory", "target_file_name.zip", 递归);

我不想处理流。 只是文件,或者更好只是文件名......

I need to (un)zip some files and after some googling I haven't found any utility for doing it. I know I can do it with built-in java.uitl.zip.* classes but isn't there any utility, that will make it easer, best like this:

SomeClass.unzip("file_name.zip", "target_directory");

or

SomeClass.zip("source_directory", "target_file_name.zip", recursively);

I don't want to handle streams. Just file, or better just file names...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮邮递员 2024-08-06 11:36:19

Deflater/Inflater 问题“什么是好的 Java 压缩库?”。

我知道Java提出的当前接口是基于流的,而不是基于“文件名”的,但根据以下文章 Java 压缩,围绕它构建一个实用程序类很容易:

例如,基于文件名的 Unzip 函数如下所示:

import java.io.*;
import java.util.zip.*;

public class UnZip {
   final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedOutputStream dest = null;
         FileInputStream fis = new 
       FileInputStream(argv[0]);
         ZipInputStream zis = new 
       ZipInputStream(new BufferedInputStream(fis));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new 
          FileOutputStream(entry.getName());
            dest = new 
              BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) 
              != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
         }
         zis.close();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}

How about the Deflater/Inflater classes mentioned in the question "What’s a good compression library for Java?".

I know the current interfaces proposed by Java are Stream-based, not "filename"-based, but according to the following article on Java compression, it is easy enough to build an utility class around that:

For instance, a Unzip function based on a filename would look like:

import java.io.*;
import java.util.zip.*;

public class UnZip {
   final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedOutputStream dest = null;
         FileInputStream fis = new 
       FileInputStream(argv[0]);
         ZipInputStream zis = new 
       ZipInputStream(new BufferedInputStream(fis));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new 
          FileOutputStream(entry.getName());
            dest = new 
              BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) 
              != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
         }
         zis.close();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}
风吹雨成花 2024-08-06 11:36:19

也许Apache Commons 的压缩可以帮助您。

Maybe Compress from Apache Commons could help you.

世界和平 2024-08-06 11:36:19

jar 是一个伪装的解压器。 那个可以用吗?

jar is a disguised unzipper. Is that usable?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文