org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.createArchiveEntry()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.createArchiveEntry()方法的一些代码示例,展示了ZipArchiveOutputStream.createArchiveEntry()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipArchiveOutputStream.createArchiveEntry()方法的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
类名称:ZipArchiveOutputStream
方法名:createArchiveEntry

ZipArchiveOutputStream.createArchiveEntry介绍

[英]Creates a new zip entry taking some information from the given file and using the provided name.

The name will be adjusted to end with a forward slash "/" if the file is a directory. If the file is not a directory a potential trailing forward slash will be stripped from the entry name.

Must not be used if the stream has already been closed.
[中]创建一个新的zip条目,从给定文件中获取一些信息,并使用提供的名称。
如果文件是目录,名称将调整为以正斜杠“/”结尾。如果文件不是目录,则条目名中可能会出现一个尾随正斜杠。
如果流已关闭,则不得使用。

代码示例

代码示例来源:origin: jphp-group/jphp

@Override
  public PArchiveEntry createEntry(Environment env, File inputFile, String entryName) throws IOException {
    return new PZipArchiveEntry(env, (ZipArchiveEntry) getWrappedObject().createArchiveEntry(inputFile, entryName));
  }
}

代码示例来源:origin: org.apache.wookie/wookie-parser

/**
   * Recursively locates and adds files and folders to a zip archive
   * @param file
   * @param out
   * @param path
   * @throws IOException
   */
  private static void pack(File file, ZipArchiveOutputStream out, String path) throws IOException {
    if(file.isDirectory()){
      path = path + file.getName() +"/";
      for(File afile: file.listFiles()){
        pack(afile,out, path);
      }
    } else {
      ZipArchiveEntry entry = (ZipArchiveEntry) out.createArchiveEntry(file, path + file.getName());
      out.putArchiveEntry(entry);
      byte[] buf = new byte[1024];
      int len;
      FileInputStream in = new FileInputStream(file);
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
       }
      out.closeArchiveEntry();
    }
  }
}

相关文章

ZipArchiveOutputStream类方法