How to identify a zip file in java?
I want to identify my archive whether it is zip or rar . But the problem I get runtime error before I can validate my file. I want to create custom notification: public class ZipValidator { public void validate(Path pathToFile) throws IOException { try { ZipFile zipFile = new ZipFile(pathToFile.toFile()); String zipname = zipFile.getName(); } catch (InvalidZipException e) { throw new InvalidZipException("Not a zip file"); } } } At the moment I have runtime error: java.util.zip.ZipException: error in opening zip file I'd suggest to open a plain InputStream an reading the first few bytes (magic