Here you can find the source of isZipFile(File file)
true
if the given file is a zip file.
public static boolean isZipFile(File file)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2015 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are 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 * * Contributors:/*from www. j a v a 2s .c om*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; public class Main { /** * @return Returns <code>true</code> if the given file is a zip file. */ public static boolean isZipFile(File file) { if (file == null || file.isDirectory() || !file.canRead() || file.length() < 4) { return false; } try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) { int test = in.readInt(); return test == 0x504b0304; // magic number of a zip file } catch (Exception e) { return false; } } }