如何在特定文件夹中添加文件(在ZIP中) [英] How to add a file in a specific folder (in the ZIP)

查看:197
本文介绍了如何在特定文件夹中添加文件(在ZIP中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码,如何使用java将文件添加到zip:

The following code, how to add a file to a zip using java:

String source = "C:/Users/XXXXX/Desktop/Helicopter.zip";
try {
  ZipFile zipFile = new ZipFile(source);

  ZipParameters parameters = new ZipParameters();

  zipFile.addFile(new File("C:/Users/XXXXXX/Desktop/HELLO_HELICOPTER.txt"), parameters);


} catch (net.lingala.zip4j.exception.ZipException e) {
  e.printStackTrace();
}

如何在此zip文件中的特定文件夹中添加文件?存档?

How am I able to add the file in a specific folder in this zip-archive?

推荐答案

我找到了解决方案:

放入文件你想添加一个特定的文件夹然后使用方法addFolder()。

Put the file you want to add in a specific folder and then use the method "addFolder()".

这个文件夹中的所有文件都将被添加,如果已经有相同的命名文件夹在zip中,您的文件夹不会被重新创建,但文件将被添加到现有文件中

All files within this folder will be added and if the same named folder is already in the zip, your folder will not be re-created, but the files will be added to the existing one

示例:

ZipFile zipFile = new ZipFile(source);
ZipParameters parameters = new ZipParameters();

zipFile.addFolder(new File("C:/Users/XXXXXX/Desktop/HELLO_Folder), parameters);

这篇关于如何在特定文件夹中添加文件(在ZIP中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆