Java 7 to the rescue!
You can either pass the file or the file name and it will return the MIME type.
String mimeType = MimetypesFileTypeMap
.getDefaultFileTypeMap()
.getContentType(attachment.getFileName());
http://docs.oracle.com/javase/7/docs/api/javax/activation/MimetypesFileTypeMap.html