Java Zip File Check isZip(File file)

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

Description

is Zip

License

Open Source License

Declaration

public static boolean isZip(File file) 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2010 - 2011 Red Hat, Inc. 
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * /*from  w  ww  .j a v  a  2s  .c  om*/
 * Contributors: 
 * Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

import java.io.BufferedInputStream;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    public static boolean isZip(File file) {
        if (file.isDirectory()) {
            return false;
        }
        if (!file.canRead()) {
            return false;
        }
        if (file.length() < 4) {
            return false;
        }
        try {
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
            int test = in.readInt();
            in.close();
            return test == 0x504b0304;
        } catch (IOException ioe) {
            return false;
        }
    }
}

Related

  1. isZip(BufferedInputStream in)
  2. isZip(byte[] bytes)
  3. isZip(File candidate)
  4. isZip(File f)
  5. isZip(File file)
  6. isZip(File file)
  7. isZip(File file)
  8. isZip(File zip)