Java Zip File Check isZipFile(File f)

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

Description

isZipFile static method test if file name matches a zip file

License

Open Source License

Parameter

Parameter Description
f -File object

Return

true if file name designated by File object is matching .zip pattern false otehrwise

Declaration

public static boolean isZipFile(File f) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    /**/*from   w  w w.  j  a v a  2  s. c om*/
     * isZipFile static method test if file name matches a zip file
     * @param f  -File object
     * @return true if file name designated by File object is matching .zip pattern false otehrwise 
     */
    public static boolean isZipFile(File f) {
        if (f == null)
            return false;

        return isZipFile(f.getName());
    }

    /**
     * isZipFile method to test if given file name matches zip file name.
     * @param str
     * @return - boolean true if file is zip type and false if it is not. 
     */
    public static boolean isZipFile(String str) {
        if (str == null)
            return false;
        if (str.length() < 3)
            return false;

        String tmp = str.substring(str.length() - 3, str.length());

        if (tmp.toLowerCase().equals("zip"))
            return true;
        else
            return false;
    }
}

Related

  1. isZip(File zip)
  2. isZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip, long zipEndOfCentralDirectoryPosition)
  3. isZipContainsEntry(File zip, String relativePath)
  4. isZipEntryPackage(String str)
  5. isZipFile(File f)
  6. isZipFile(File f)
  7. isZipFile(File f)
  8. isZipFile(File f)
  9. isZipFile(File file)