私は時々、私は正確に特定することはできませんエラーJavaのエキスのzip予期しない終了
java.lang.Exception: java.io.EOFException: Unexpected end of ZLIB input stream
を取得し、zipファイルを抽出してデータベースにファイルを挿入するプログラムを作成していますこれは抽出コードとしての理由は、Web上で見つけることができる他のコードとほとんど同じです。私のコードは次の通りです:
public void extract(String zipName, InputStream content) throws Exception {
int BUFFER = 2048;
//create the zipinputstream
ZipInputStream zis = new ZipInputStream(content);
//Get the name of the zip
String containerName = zipName;
//container for the zip entry
ZipEntry entry;
// Process each entry
while ((entry = zis.getNextEntry()) != null) {
//get the entry file name
String currentEntry = entry.getName();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// establish buffer for writing file
byte data[] = new byte[BUFFER];
int currentByte;
// read and write until last byte is encountered
while ((currentByte = zis.read(data, 0, BUFFER)) != -1) {
baos.write(data, 0, currentByte);
}
baos.flush(); //flush the buffer
//this method inserts the file into the database
insertZipEntry(baos.toByteArray());
baos.close();
}
catch (Exception e) {
System.out.println("ERROR WITHIN ZIP " + containerName);
}
}
}
•処理しようとしているZIPストリーム(ファイル)が有効であることを確認しましたか(たとえば、「unzip」で解凍できますか? •実際に例外を発生させたコードの行を特定してください。 –
私は正しく覚えていないかもしれませんが、それを処理した後に各エントリを閉じるはずがありませんか? – biziclop
insertZipEntry()を呼び出す前にbaosを閉じて、 'currentByte'変数の名前が正しくない: 'count'かそれに類するものでなければなりません。 – EJP