写的ZipEntry数据至字符串 [英] Write ZipEntry Data To String

查看:220
本文介绍了写的ZipEntry数据至字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也取自像这样一个zip文件的zip条目。

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

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

ZipEntry entry;
try {
    while ((entry = zis.getNextEntry())!= null) {

    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

这工作正常,它让我的的ZipEntry 没有问题。

This works fine and its getting my ZipEntry no problem.

我的提问

如何获得这些 ZipEntries 的内容为一个字符串,因为它们是 XML CSV 文件。

How to get the contents of these ZipEntries into a String as they are xml and csv files.

推荐答案

您必须从读 ZipInputStream

StringBuilder s = new StringBuilder();
byte[] buffer = new byte[1024];
int read = 0;
while ((entry = zis.getNextEntry())!= null) {
      while ((read = zis.read(buffer, 0, 1024)) >= 0) {
           s.append(new String(buffer, 0, read));
      }
}

当你从出口的内部,而保存的StringBuilder 的内容,并将其复位。

When you exit from the inner while save the StringBuilder content, and reset it.

这篇关于写的ZipEntry数据至字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆