【发布时间】:2020-03-22 22:04:52
【问题描述】:
我有这个代码可以压缩成 zip 格式的一些文件:
public int zip(List<String> _files, String zipFileName) {
try {
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(zipFileName);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(
dest));
byte data[] = new byte[BUFFER];
for (int i = 0; i < _files.size(); i++) {
Log.v("Compress", "Adding: " + _files.get(i));
FileInputStream fi = new FileInputStream(_files.get(i));
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(_files.get(i).substring(_files.get(i).lastIndexOf(File.separator) + 1));
out.putNextEntry(entry);
int count;
while ((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}
我想获取 ZipOutPutStream 并通过 Intent 或其他方式发送它,而不是像这样保存:
while ((count = origin.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
有办法吗?目前我只能使用其保存的名称作为字符串发送 zip。
【问题讨论】: