如何将ZipInputStream转换为InputStream?

我有将ZipInputSream转换为byte []的代码,但我不知道如何将其转换为inputstream

private void convertStream(String encoding, ZipInputStream in) throws IOException,

UnsupportedEncodingException

{

final int BUFFER = 1;

@SuppressWarnings("unused")

int count = 0;

byte data[] = new byte[BUFFER];

while ((count = in.read(data, 0, BUFFER)) != -1)

{

// How can I convert data to InputStream here ?

}

}

回答:

这是我解决此问题的方法。现在,我可以将单个文件从ZipInputStream作为InputStream传输到内存。

private InputStream convertZipInputStreamToInputStream(ZipInputStream in, ZipEntry entry, String encoding) throws IOException

{

final int BUFFER = 2048;

int count = 0;

byte data[] = new byte[BUFFER];

ByteArrayOutputStream out = new ByteArrayOutputStream();

while ((count = in.read(data, 0, BUFFER)) != -1) {

out.write(data);

}

InputStream is = new ByteArrayInputStream(out.toByteArray());

return is;

}

以上是 如何将ZipInputStream转换为InputStream? 的全部内容, 来源链接: utcz.com/qa/432841.html

回到顶部