Asked By : Kurt
Answered By : Vor
- first you can try to display it as a text file (like suggested by saadtaame in his answer): many file formats (text data, html files, xml files, …) store the information in plain text (ASCII);
- or you can change its extension (.pdf, .jpg, .mp3, .gif, .avi, …), and try to open it with some standard programs … if you are lucky you’ll find one that opens it correctly;
- or you can do something smarter. You can examine the first bytes of the file (header): they usually have a particular structure or contains specific fixed characters that allow you to quickly find the file format of the whole file.
For example the bytes 6,7,8,9 of a JPEG file are always 0x4a 0x46 0x49 0x46, which correspond to the string “JFIF” in ASCII. Windows PE executables contain the string “This program cannot …” in the header. The first two bytes of a file in ZIP format are “PK”, and so on … But there are thousands of file formats out there, so you can also consider using a computer program that given an unknown file can help you to find its file format automatically. Finally don’t forget that the information in a file can also be encrypted or the file format can be proprietary (and closed, i.e. undocumented); in these cases there are very little probability (zero?) to decode the information stored in the files.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/10944