Java Path File Check nio isZipFile(Path path)

Here you can find the source of isZipFile(Path path)

Description

Check if the file matching the given path is a zip file or not.

License

Apache License

Parameter

Parameter Description
path The patch to check.

Declaration

public static boolean isZipFile(Path path) 

Method Source Code


//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;
        }
    }
}

Related

  1. isValidWildFlyHome(final Path path)
  2. isVideo(Path p)
  3. isZip(Path path)
  4. isZip(Path path)
  5. isZipFile(Path path)