【发布时间】:2019-01-27 01:33:38
【问题描述】:
以下是将字节保存到 .png 文件并压缩到给定名称文件夹中的程序。
byte[] decodedBytes = Base64.decodeBase64(contents);
// System.out.println(new String(decodedBytes));
InputStream targetStream = new ByteArrayInputStream(decodedBytes);
int count;
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilePath));
out.putNextEntry(new ZipEntry(pngFile));
byte[] b = new byte[1024];
while ((count = targetStream.read(b)) > 0) {
out.write(b, 0, count);
}
out.flush();
out.close();
targetStream.close();
当我使用 7 zip 手动打开它时,我看到以下文件夹结构 (c:\output\nameofzipfile.zip\nameofpng.png\nameofpng)。为什么会这样?我究竟做错了什么?据我了解,这应该是结构 (c:\output\nameofzipfile.zip\nameofpng.png)
【问题讨论】: