Here you can find the source of isZipFile(Path path)
Parameter | Description |
---|---|
path | The patch to check. |
public static boolean isZipFile(Path path)
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.file.*; public class Main { /**/* ww w . ja v a 2 s.c o m*/ * Check if the file matching the given path is a zip file or not. * * @param path The patch to check. */ public static boolean isZipFile(Path path) { File f = path.toFile(); if (f.isDirectory() || f.length() < 4) { return false; } try (DataInputStream inputStream = new DataInputStream(new FileInputStream(f))) { return inputStream.readInt() == 0x504b0304; } catch (FileNotFoundException e) { return false; } catch (IOException e) { return false; } } }