import java.io.File;
import java.io.IOException;
import java.util.zip.ZipFile;
import java.util.zip.ZipException;
public class testlog4j {
public static void main(String[] args) {
System.out.println(testlog4j.isCorrupted("C:\\Trigger\\file_corrupted_inside.zip"));
System.out.println(testlog4j.isCorrupted("C:\\Trigger\\corruptedfile.zip"));
}
public static boolean isCorrupted(final String string) {
ZipFile zipfile = null;
try {
zipfile = new ZipFile(string);
return false;
} catch (ZipException e) {
System.out.println(e);
return true;
} catch (IOException e) {
System.out.println(e);
return true;
} finally {
try {
if (zipfile != null) {
zipfile.close();
zipfile = null;
}
} catch (IOException e) {
System.out.println(e);
}
}
}
文件\u corrupted\u inside.zip中有1个损坏的word文件,但我可以压缩它并打开*.zip文件。
corruptedfile.zip是一个损坏的zip文件,我们无法打开它。结果是:
false
java.util.zip.ZipException: error in opening zip file
true
暂无答案!
目前还没有任何答案,快来回答吧!