Java Zip File Check isZipFile(File file)

Here you can find the source of isZipFile(File file)

Description

Determine whether a file is a ZIP File.

License

Open Source License

Declaration

public static boolean isZipFile(File file) throws IOException 

Method Source Code

//package com.java2s;
/**/*  w w w.jav  a 2  s  . c  om*/
 * License: https://github.com/votingsystem/votingsystem/wiki/Licencia
 */

import java.io.*;

public class Main {
    /**
     * Determine whether a file is a ZIP File.
     */
    public static boolean isZipFile(File file) throws IOException {
        if (file.isDirectory()) {
            return false;
        }
        if (!file.canRead()) {
            throw new IOException("Cannot read file " + file.getAbsolutePath());
        }
        if (file.length() < 4) {
            return false;
        }
        DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
        int test = in.readInt();
        in.close();
        return test == 0x504b0304;
    }
}

Related

  1. isZipFile(File f)
  2. isZipFile(File f)
  3. isZipFile(File f)
  4. isZipFile(File f)
  5. isZipFile(File file)
  6. isZipFile(File file)
  7. isZipFile(File file)
  8. isZipFile(File file)
  9. isZipFile(File file)