If you have Java 7, then you can make use of Files.probeContentType(path).
import java.nio.file.*;
 public class MimeTypes {
       public static void main(String[] args) {
          Path path;
          try {
             path = Paths.get("/etc");  
             System.out.println( path + " : " + Files.probeContentType(path) );
             path = Paths.get("/dev/null");  
             System.out.println( path + " : " + Files.probeContentType(path) );
             path = Paths.get("/var/log/syslog.2.gz");  
             System.out.println( path + " : " + Files.probeContentType(path) );
             path = Paths.get("/var/run/rpcbind.sock");  
             System.out.println( path + " : " + Files.probeContentType(path) );
             path = Paths.get("abc.mp4");  
             System.out.println( path + " : " + Files.probeContentType(path) );
             path = Paths.get("MimeTypes.java");  
             System.out.println( path + " : " + Files.probeContentType(path) );
          } catch (Exception x) {
          }
       }
    }
Output:
# java MimeTypes 
/etc : inode/directory
/dev/null : inode/chardevice
/var/log/syslog.2.gz : application/x-gzip
/var/run/rpcbind.sock : inode/socket
abc.mp4 : video/mp4
MimeTypes.java : text/x-java
Oracle documentation of Files is here.
Another option: Apache Tika 
Apache Tika is a toolkit for detecting and extracting metadata and structured text content from various documents using existing parser libraries. Tika has a lot of dependencies ... almost 20 jars ! But it can do a lot more than detecting filetype. For example, you can parse a PDF or DOC to extract the text and the metadata very easily. 
public static void main(String args[]) throws Exception {
    FileInputStream is = null;
    try {
      File f = new File("C:/Temp/mime/abc.mp4");
      is = new FileInputStream(f);
      ContentHandler contenthandler = new BodyContentHandler();
      Metadata metadata = new Metadata();
      metadata.set(Metadata.RESOURCE_NAME_KEY, f.getName());
      Parser parser = new AutoDetectParser();
      // OOXMLParser parser = new OOXMLParser();
      parser.parse(is, contenthandler, metadata);
      System.out.println("Mime: " + metadata.get(Metadata.CONTENT_TYPE));
      System.out.println("Title: " + metadata.get(Metadata.TITLE));
      System.out.println("Author: " + metadata.get(Metadata.AUTHOR));
      System.out.println("content: " + contenthandler.toString());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
        if (is != null) is.close();
    }
  }