Some files have a little "signature" at the beginning, like Java class files all start with x'CAFEBABE. I don't know a good catalog of these, but there aren't many compared to the number of file types in the world and they would be easy to fake if somebody wanted to confuse you.
Is that the kind of thing you're after?
JavaBeans Activation Framework (JAF) is a standard extension to the Java platform that lets you take advantage of standard services to: determine the type of an arbitrary piece of data; encapsulate access to it; discover the operations available on it; and instantiate the appropriate bean to perform the operation(s).
I haven't tried it out, but you should be able to use that to detect the MIME type of a file like this: