title: Best way to determine mime type of a file in java?
body: <p>Curious what the best way is in Java to get the mime-type of a file. It should actually inspect the file because filenames aren't an accurate indicator. </p>
  
  <p>Currently I'm using the following which seems to be very hit or miss</p>
  
  <pre><code>  is = new BufferedInputStream(new FileInputStream(fileName));
    String mimeType = URLConnection.guessContentTypeFromStream(is);
    if(mimeType == null) {
      throw new IOException("can't get mime type of image");
    }
  </code></pre>