开发者

Magic number file checking

I'm attempting to read magic numbers/bytes to check the format of 开发者_Go百科a file. Will reading a file byte by byte work in the same way on a Linux machine?

Edit: The following shows to get the magic bytes from a class file using an int. I'm trying to do the same for a variable number of bytes.

http://www.rgagnon.com/javadetails/java-0544.html


I'm not sure that I understand what you are trying to do, but it sounds like what you are trying to do isn't the same thing as what the code that you are linking to is doing.

The java class format is specified to start with a magic number, so that code can only be used to verify if a file might be a java class or not. You can't use the same logic and apply it to arbritraty file formats.

Edit: .. or do you only want to check for wav files?

Edit2: Everything in Java is in big endian, that means that you can use DataInputStream.readInt to read the first four bytes from the file, and then compare the returned int with 0x52494646 (RIFF as a big endian integer)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜