How can I read the first two bytes of a .zip file to confirm that the appropriate magic number is present?

StackOverflow https://stackoverflow.com/questions/20344269

Pergunta

I'm trying to read in a .zip file that holds a compressed .txt file. How can I check for the magic number 0x00BC? Thanks.

Edit: Sorry, should have specified that I'm trying to do this in java.

Foi útil?

Solução

First two bytes from the ZIP file:

InputStream is = new FileInputStream(FILE NAME);
byte b1 = (byte)is.read();
byte b2 = (byte)is.read();
is.close();

First two bytes from the first compressed file:

InputStream is = new FileInputStream(FILE NAME);
ZipInputStream zis = new ZipInputStream(is);
zis.getNextEntry();
byte[] bytes = new byte[2];
zis.read(bytes, 0, 2);
zis.close();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top