Source Code : Determine whether a file is a JAR File.

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Determine whether a file is a JAR File.

  
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipFile;

public class Main {

  /**
   * Determine whether a file is a JAR File.
   */
  public static boolean isJarFile(File file) throws IOException {
    if (!isZipFile(file)) {
      return false;
    }
    ZipFile zip = new ZipFile(file);
    boolean manifest = zip.getEntry("META-INF/MANIFEST.MF") != null;
    zip.close();
    return manifest;
  }
  /**
   * Determine whether a file is a ZIP File.
   */
  public static boolean isZipFile(File file) throws IOException {
      if(file.isDirectory()) {
          return false;
      }
      if(!file.canRead()) {
          throw new IOException("Cannot read file "+file.getAbsolutePath());
      }
      if(file.length() < 4) {
          return false;
      }
      DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
      int test = in.readInt();
      in.close();
      return test == 0x504b0304;
  }
}

   
    
  

Thank with us