Determine the file type based on the first few bytes of the file content

Source: Internet
Author: User

Determine with the file header. Directly read the first few bytes of the file. </P> <p> the file headers of common files are as follows: <br/> JPEG (JPG), file header: ffd8ff <br/> PNG (PNG), and file header: 89504e47 <br/> GIF (GIF), file header: 47494638 <br/> tiff (TIF), file header: 49347a00 <br/> Windows Bitmap (BMP), file header: development d <br/> CAD (DWG), file header: 41433130 <br/> Adobe Photoshop (PSD), file header: 38425053 <br/> Rich Text Format (RTF), file header: 7b5c727466 <br/> XML (XML), file header: 3c3f786d6c <br/> HTML (HTML), file header: 68746d6c3e <br/> email [thorough only] (EML), file header: outlook Express (DBX), file header: cfad12fec5fd746f <br/> Outlook (PST), file header: 2142444e <br/> MS Word/Excel (xls.or.doc), file header: d0cf11e0 <br/> MS Access (MDB), file header: 5374616e64617424204a <br/> Wordperfect (WPD), file header: ff575043 <br/> postscript (EPS. or. PS), file header: 252150532d41646f6265 <br/> Adobe Acrobat (PDF), file header: 255044462d312e <br/> quicken (qdf), file header: ac9ebd8f <br/> Windows Password (pwl), file header: e3828596 <br/> ZIP Archive (ZIP), file header: 504b0304 <br/> RAR Archive (RAR), file header: 52617221 <br/> wave (WAV), file header: 57415645 <br/> AVI (AVI), file header: 41564920 <br/> Real Audio (RAM), file header: 2e00001fd <br/> Real Media (RM), file header: 2e524d46 <br/> MPEG (MPG), file header: 000001ba <br/> MPEG (MPG), file header: 000001b3 <br/> QuickTime (mov), file header: 6d6f6f76 <br/> Windows Media (ASF), file header: 3026b2758e66cf11 <br/> Midi (MID), file header: 4d546864 </P> <p> package Org. test; </P> <p> Import Java. io. fileinputstream; </P> <p> public class test {</P> <p> Public static string bytestohexstring (byte [] SRC) {<br/> stringbuilder = new stringbuilder (); <br/> If (src = NULL | SRC. length <= 0) {<br/> return NULL; <br/>}< br/> for (INT I = 0; I <SRC. length; I ++) {<br/> int v = SRC [I] & 0xff; <br/> string HV = integer. tohexstring (V); <br/> If (HV. length () <2) {<br/> stringbuilder. append (0); <br/>}< br/> stringbuilder. append (HV); <br/>}< br/> return stringbuilder. tostring (); <br/>}</P> <p>/** <br/> * @ Param ARGs <br/> */<br/> Public static void main (string [] ARGs) throws exception {<br/> fileinputstream is = new fileinputstream ("D: // face.jpg"); <br/> byte [] B = new byte [3]; <br/> is. read (B, 0, B. length); <br/> system. out. println (bytestohexstring (B); </P> <p >}< br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.