Javaでzipファイルを開き、zip内のExcelファイルを動的に処理するメソッドを作成しています。Java で API ZipFile を使用しており、zipfile をファイル システムに抽出せずにメモリ内でそのまま処理したいと考えています。
これまでのところ、zip ファイルを反復処理することはできますが、zip ファイル内のディレクトリの下にあるファイルを一覧表示するのに問題があります。Excel ファイルは、zip ファイル内のフォルダーに入れることができます。以下は、私が問題を抱えているセクションにコメントを付けた現在のコードです。どんな助けでも大歓迎です:)
public static void main(String[] args) {
try {
ZipFile zip = new ZipFile(new File("C:\\sample.zip"));
for (Enumeration e = zip.entries(); e.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) e.nextElement();
String currentEntry = entry.getName();
if (entry.isDirectory()) {
/*I do not know how to get the files underneath the directory
so that I can process them */
InputStream is = zip.getInputStream(entry);
} else {
InputStream is = zip.getInputStream(entry);
}
}
} catch (ZipException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}