Here you can find the source of getZipEntryContent(final File zip, final String entry)
Parameter | Description |
---|---|
zip | zip. |
entry | entry. |
Parameter | Description |
---|---|
IOException | error while reading. |
InterruptedException | task cancelled. |
public static String getZipEntryContent(final File zip, final String entry) throws IOException, InterruptedException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main { /**/*from w w w . j a va 2s . c o m*/ * Get the content of a zip entry. * * @param zip * zip. * @param entry * entry. * @return its content. * @throws IOException * error while reading. * @throws InterruptedException * task cancelled. */ public static String getZipEntryContent(final File zip, final String entry) throws IOException, InterruptedException { try (ZipFile f = new ZipFile(zip)) { final ZipEntry e = f.getEntry(entry); final InputStream is = f.getInputStream(e); final BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; final StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { // Check for interrupt. if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); } // Read next line. sb.append(line); } return sb.toString(); } } }