Java Zip File Check isZipFile(String fileName)

Here you can find the source of isZipFile(String fileName)

Description

Determine whether the file with the given filename is in .zip or .jar format.

License

Open Source License

Parameter

Parameter Description
fileName file to test

Return

true if the file is in tar format

Declaration

public static boolean isZipFile(String fileName) 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.io.IOException;
import java.util.zip.ZipFile;

public class Main {
    /**/*w  w w. j  ava2 s .c  om*/
     * Determine whether the file with the given filename is in .zip or .jar format.
     * 
     * @param fileName file to test
     * @return true if the file is in tar format
     */
    public static boolean isZipFile(String fileName) {
        if (fileName == null || fileName.trim().length() == 0) {
            return false;
        }

        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(fileName.trim());
        } catch (IOException ioException) {
            return false;
        } finally {
            if (zipFile != null) {
                try {
                    zipFile.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }

        return true;
    }
}

Related

  1. isZipFile(File file)
  2. isZipFile(File file)
  3. isZipFile(File file)
  4. isZipFile(InputStream stream)
  5. isZipFile(java.io.File file)
  6. isZipFile(String fileName)
  7. isZipFile(String path)
  8. isZipOrJarArchive(File file)
  9. isZipped(File f)