Question

I have this code which enables me to read a zip file content, but I want instead to read a directory content instead of a zip file (the zip file must be seen as a directory). What should I do ?

import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ZipFileDataReader {
    private ZipFile zipFile;
    private Map zipEntry2dataReader;

    public ZipFileDataReader(ZipFile zipFile) {
        this.zipFile = zipFile;
        zipEntry2dataReader = new HashMap();
    }

    public synchronized ZipEntryDataReader getZipEntryDataReader(
            ZipEntry zipEntry, long offset, int size) {
        ZipEntryDataReader entryReader = (ZipEntryDataReader) zipEntry2dataReader
                .get(zipEntry.getName());

        if (entryReader == null) {
            entryReader = new ZipEntryDataReader(zipFile, zipEntry);
            zipEntry2dataReader.put(zipEntry.getName(), entryReader);
        }

        return entryReader;
    }

    public synchronized void releaseZipEntryDataReader(ZipEntry zipEntry) {
        zipEntry2dataReader.remove(zipEntry.getName());
    }
}
Was it helpful?

Solution

Here's a nice big guide on Java File IO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top