List of utility methods to do Zip File Check
boolean | isZipFile(java.io.File file) Checks is specified file is zip file or not. if (file.isDirectory()) { return false; byte[] bytes = new byte[4]; try (FileInputStream fIn = new FileInputStream(file)) { if (fIn.read(bytes) != 4) { return false; final int header = bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24); return 0x04034b50 == header; |
boolean | isZipFile(String fileName) Determine whether the file with the given filename is in .zip or .jar format. if (fileName == null || fileName.trim().length() == 0) { return false; ZipFile zipFile = null; try { zipFile = new ZipFile(fileName.trim()); } catch (IOException ioException) { return false; ... |
boolean | isZipFile(String fileName) is Zip File if (fileName == null) { return false; File file = new File(fileName); if (!file.exists() || !file.isFile()) { return false; InputStream in = null; ... |
boolean | isZipFile(String path) is Zip File if (path == null) return false; try { new ZipFile(path).close(); ; return true; } catch (IOException e) { return false; ... |
boolean | isZipOrJarArchive(File file) Test if a file is a ZIP or JAR archive. boolean isArchive = true; ZipFile zipFile = null; try { zipFile = new ZipFile(file); } catch (ZipException zipCurrupted) { isArchive = false; } catch (IOException anyIOError) { isArchive = false; ... |
boolean | isZipped(File f) Checks if a file is zipped. try { RandomAccessFile raf = new RandomAccessFile(f, "r"); long n = raf.readInt(); raf.close(); if (n == 0x504B0304) { return true; } else { return false; ... |
boolean | isZipped(File file) is Zipped try { return new ZipInputStream(new FileInputStream(file)).getNextEntry() != null; } catch (IOException e) { return false; |
boolean | isZipped(final File file) is Zipped final String name = file.getName().toLowerCase(); for (String ext : extList) { if (name.endsWith(ext)) return true; return false; |
boolean | isZipped(InputStream inputStream) Checks the first four bytes of a given resource and determines if it is zipped or not. DataInputStream dis = new DataInputStream(inputStream); try { return dis.readInt() == 0x504b0304; } catch (EOFException e) { return false; } finally { dis.close(); |
boolean | isZipped(String name) Returns true if file is in Zip format and false if it is not. long n = 0x0; File file = null; RandomAccessFile raf = null; try { try { file = new File(name); if (!file.exists()) { return false; ... |