0

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());
    }
}
TheForbidden
  • 1,533
  • 4
  • 22
  • 30
  • 1
    Do you want to read the directory in which the zip file is placed ? I couldn't understand this statement"read a directory content instead of a zip file (the zip file must be seen as a directory)". Can you explain this>? – karthick Mar 29 '13 at 10:48
  • I mean, I want to get rid of the zipfile, I want to read a directory. I finded how to read a zipfile in this way but I couldn't find how to read a directory – TheForbidden Mar 29 '13 at 10:50
  • I mean, can I cast the zipfile to a directory ?! – TheForbidden Mar 29 '13 at 11:06
  • You can't the only way to do is extract the zip file and then read the contents of the directory. – karthick Mar 29 '13 at 11:08

1 Answers1

0

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

CapnSmack
  • 232
  • 1
  • 4