本文整理了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
[英]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();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!