Java Is Jar File isJar(File file)

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

Description

Is the file a JAR?

License

Open Source License

Parameter

Parameter Description
file a parameter

Declaration

public static boolean isJar(File file) 

Method Source Code

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

import java.io.File;

import java.io.IOException;

import java.util.jar.JarFile;

public class Main {
    /**/*from  w  w  w. j a va  2  s . c  om*/
     * Is the file a JAR?
     *
     * @param file
     * @return
     */
    public static boolean isJar(File file) {
        //TODO: bad style to write code that depends on exceptions
        try {
            JarFile jarFile = new JarFile(file); // throws IOException if not a jar file
            jarFile.close(); // don't rely on finalize to close
            return true;
        } catch (IOException e) {
            return false;
        }
    }
}

Related

  1. isJar(File file)
  2. isJar(File file)
  3. isJar(final File element)
  4. isJar(InputStream is)
  5. isJar(String file)