You can check the valid gzip header in the file. The gzip file must contain a specific header starting with a 2-byte number with the values ββ0x1f and 0x8b (see spec ). You can check these bytes to see if they match the header values:
InputStream is = new FileInputStream(new File(filePath));
byte[] b = new byte[2];
int n = is.read(b);
if ( n != 2 ){
}
if ( (b[0] == (byte) 0x1f) && (b[1] == (byte)0x8b)){
}
1/65k, , , , . , , , (. - , , 8 DEFLATE ...)