Write ZipEntry Data To String

前端 未结 4 1552
你的背包
你的背包 2021-02-05 20:16

I have retrieved a zip entry from a zip file like so.

InputStream input = params[0];
ZipInputStream zis = new ZipInputStream(input);

ZipEntry entry;
try {
    w         


        
4条回答
  •  长情又很酷
    2021-02-05 20:52

    Here is the approach, which does not break Unicode characters:

    final ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(content));
    final InputStreamReader isr = new InputStreamReader(zis);
    final StringBuilder sb = new StringBuilder();
    final char[] buffer = new char[1024];
    
    while (isr.read(buffer, 0, buffer.length) != -1) {
        sb.append(new String(buffer));
    }
    
    System.out.println(sb.toString());
    

提交回复
热议问题