This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma 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.