Get file in folder in zip as string in java
<p>I can get a text file as <code>String</code> with <code>new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8)</code>. How do I achieve the same result if the file is in a folder which is in a zip file? I know I can get the zip as a <code>ZipFile</code> and the folder as a <code>ZipEntry</code> but I'm not clear on how I get the file nor how I make a <code>String</code> out of it. I don't want to create any files or folders to get it.</p>

<p>EDIT: Per dpr's answer, here's what I used:</p>

<pre><code>String fileAsString;
try (ZipFile zip = new ZipFile(path)) {
    ZipEntry entry = zip.getEntry("folder/file.txt");
    if (entry == null) entry = zip.getEntry("folder\\file.txt");
    try (InputStream is = zip.getInputStream(entry)) {
        try (Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A")) {
            fileAsString = s.hasNext() ? s.next() : "";
        }
    }
}
</code></pre>