将字符串写入zip中的文件,而不在磁盘上创建文件。JAVA

将字符串写入zip中的文件,而不在磁盘上创建文件。JAVA,java,zip,Java,Zip,我需要从zip“Inputs”存档中读取(需要做其他事情)所有txt文件,并保存到其他“Result”,而无需将文件解压缩到磁盘,所有这些都需要在memmory中“动态”执行。 使用ZipInputStream/ZipOutStream读取文件 问题是写入结果zip文件。我尝试: String zipEntryString = toStringZipEntry(zis); // Read file to string String parcedStringFile = par

我需要从zip“Inputs”存档中读取(需要做其他事情)所有txt文件,并保存到其他“Result”,而无需将文件解压缩到磁盘,所有这些都需要在memmory中“动态”执行。 使用ZipInputStream/ZipOutStream读取文件

问题是写入结果zip文件。我尝试:

String zipEntryString = toStringZipEntry(zis);           // Read file to string
String parcedStringFile = parceContacts(zipEntryString); // Just return the same string at this moment nothing do

// Try write to string resultZip
InputStream is = new  ByteArrayInputStream(parcedStringFile.getBytes(ENCODING));
zos.putNextEntry(zipEntry);

int bufferSize;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bufferSize = is.read(buffer, 0, buffer.length)) != -1) {
   zos.write(buffer, 0, bufferSize);
}

// Also try in whis way
// byte[] stringBytes = parcedStringFile.getBytes();
// zos.putNextEntry(zipEntry);
// zos.write(stringBytes);

is.close();
因此,我使用以下内容创建文件:

2b37 2028 3130 3129 2031 3131 2d32 3232
2d31 3120 2061 6263 4065 7274 2e63 6f6d
2c20 6465 6640 7364 662e 6f72 670d 0a2b
3120 2831 3032 2920 3132 3335 3332 2d32
... 
0000 0000 0000 0000 0000 0000 0000 0000
正如我看到的,文件写入字节而不是字符串


我应该做错什么?我错过了什么?

您可以使用内存中的文件系统库,比如由google开发的,是同类库中最好的库之一

成立

int ch;
while ((ch = is.read()) != 0) {
  zos.write(ch);
}