我的目标是对文件进行编码并将其压缩到java文件夹中。我必须使用Apache的Commons-codec库。我能够编码和压缩它,它工作正常,但是当我解码它回到它的原始形式,它看起来像文件尚未完全编码。看起来有几个部分不见了。有人能告诉我为什么会发生这种情况吗?Base64-编码文件并对其进行压缩
我也附上我的代码的一部分供您参考,以便您可以相应地指导我。
private void zip() {
int BUFFER_SIZE = 4096;
byte[] buffer = new byte[BUFFER_SIZE];
try {
// Create the ZIP file
String outFilename = "H:\\OUTPUT.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
// Compress the files
for (int i : list.getSelectedIndices()) {
System.out.println(vector.elementAt(i));
FileInputStream in = new FileInputStream(vector.elementAt(i));
File f = vector.elementAt(i);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(f.getName()));
// Transfer bytes from the file t