问题的前提是,我创建了一个不应该写入磁盘的ini文件,但是这个“文件”需要以某种方式被压缩,另外,这个文件需要写在一个文件夹中,而不是在压缩的文件中,例如文件夹/file.ini。
我最初的想法是只将该文件创建到一个ByteArrayOutputStream中,这将满足不将该文件写入磁盘的要求。
然而,在压缩文件时,我认为它需要存在于磁盘上,即使只是为了提供文件名。
我有办法做到这一点吗?
发布于 2014-04-03 14:17:00
是的,你可以用ZipOutputStream之类的东西-
ZipOutputStream zs = null;
try {
zs = new ZipOutputStream(os); // Where os is your ByteArrayOutputStream
ZipEntry e = new ZipEntry(fileName); // fileName is your file (in the zip)
zs.putNextEntry(e);
zs.write(theContent); // theContent is the the file content.
} finally {
if (zs != null) {
zs.close();
}
}https://stackoverflow.com/questions/22840289
复制相似问题