is Zip File by its content - Java File Path IO

Java examples for File Path IO:Zip File

Description

is Zip File by its content

Demo Code


//package com.java2s;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static void main(String[] argv) throws Exception {
        File f = new File("Main.java");
        System.out.println(isZip(f));
    }//from  w w w  .ja  v  a  2  s  . c o m

    public static boolean isZip(final File f) throws IOException {
        // String absoluteName = f.getAbsolutePath();
        FileInputStream fis = null;
        boolean returnValue = false;
        try {
            fis = new FileInputStream(f);
            final CheckedInputStream cis = new CheckedInputStream(fis,
                    new CRC32());
            final ZipInputStream zis = new ZipInputStream(
                    new BufferedInputStream(cis));
            final ZipEntry ze = zis.getNextEntry();
            returnValue = false;

            if (ze != null) {
                returnValue = true;
            }
        } finally {
            if (fis != null) {
                fis.close();
            }
        }
        return returnValue;
    }
}

Related Tutorials