Issue
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();
}
This works fine and its getting my ZipEntry
no problem.
My Question
How can I get the contents of these ZipEntries
into a String as they are xml and csv files.
Solution
you have to read from the ZipInputStream
:
StringBuilder s = new StringBuilder();
byte[] buffer = new byte[1024];
int read = 0;
ZipEntry entry;
while ((entry = zis.getNextEntry())!= null) {
while ((read = zis.read(buffer, 0, 1024)) >= 0) {
s.append(new String(buffer, 0, read));
}
}
When you exit from the inner while
save the StringBuilder
content, and reset it.
Answered By - Blackbelt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.