Java Zip File Check isZipFile(File file)

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

Description

Returns true if the input file is a zip file.

License

Open Source License

Parameter

Parameter Description
file a parameter

Return

true if the file is a zip file, false otherwise

Declaration

private static boolean isZipFile(File file) 

Method Source Code


//package com.java2s;

import java.io.File;

public class Main {
    /**/*from w  w w.  j a v a  2  s .c om*/
     * suffix signifying a zip file
     */
    private static final String zip_suffix = ".zip";

    /**
     * Returns true if the input file is a zip file. Determination is made by examining the file
     * suffix.
     * 
     * @param file
     * @return true if the file is a zip file, false otherwise
     */
    private static boolean isZipFile(File file) {
        return hasCaseInsensitiveSuffix(file, zip_suffix);
    }

    /**
     * Matches the file suffix to the input file in a case-insensitive manner
     * 
     * @param file
     * @param fileSuffix
     * @return true if the input file has the specified file suffix regardless of upper/lower case
     */
    private static boolean hasCaseInsensitiveSuffix(File file, String fileSuffix) {
        return file.getName().endsWith(fileSuffix.toLowerCase())
                || file.getName().endsWith(fileSuffix.toUpperCase());
    }
}

Related

  1. isZipFile(File f)
  2. isZipFile(File f)
  3. isZipFile(File file)
  4. isZipFile(File file)
  5. isZipFile(File file)
  6. isZipFile(File file)
  7. isZipFile(File file)
  8. isZipFile(File file)
  9. isZipFile(File file)