This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
It's sometimes possible to tell the type of a file based on its content. One way is to check the magic number, though not all file types have one, and there's no guarantee there won't be conflicts (though it's statistically improbable). For example, GIF files all start with the ASCII string GIF87a or GIF89a. A text file or pure binary file might also begin with this combination, but it's unlikely. Wikipedia will give you a place to start.