读取目录内容而不是zip文件内容

时间:2013-03-29 10:45:48

标签: java directory zipfile fuse

我有这个代码,它使我能够读取zip文件内容,但我想要读取目录内容而不是zip文件(zip文件必须被视为目录)。我该怎么办?

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());
    }
}

1 个答案:

答案 0 :(得分:0)

这是关于Java File IO的精彩指南。