Obviously, the easiest thing to do is look at the filename extension. Of course, it's not necessarily reliable, but it may suffice in some circumstances.
Short of reading the whole image, you could read the first few bytes of the file to identify it by its "magic number". For example, JPEG files always start with the two bytes 0xFFD8 and end with 0xFFD9; PDFs always begin with the string "%PDF".
This saves you the overhead of creating an image in memory, and might speed up your I/O as well (since you only need a few bytes of the file).
If you don't want to research all these magic numbers yourself, you could try a library such as jMimeMagic. I've never used it, so I can't vouch for its quality or completeness, but it is LGPL. I'm sure you can find other alternatives as well.