Here you can find the source of isZipFile(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static boolean isZipFile(File file) throws IOException
//package com.java2s; /**/* w w w.j a v a2 s. c om*/ * This program and the accompanying materials * are made available under the terms of the License * which accompanies this distribution in the file LICENSE.txt */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { /** * @param file * @return True if file is an archive zip file * @throws IOException */ public static boolean isZipFile(File file) throws IOException { // Signature first 4 bytes of zip file final byte[] sig = new byte[] { 0x50, 0x4B, 0x3, 0x4 }; if (file.canRead()) { byte[] buf = new byte[4]; FileInputStream is = null; try { is = new FileInputStream(file); is.read(buf); } finally { if (is != null) { is.close(); } } for (int i = 0; i < buf.length; i++) { if (buf[i] != sig[i]) { return false; } } return true; } return false; } }