Getting A File's Mime Type In Java

Lee Theobald picture Lee Theobald · Sep 9, 2008 · Viewed 399.2k times · Source

I was just wondering how most people fetch a mime type from a file in Java? So far I've tried two utils: JMimeMagic & Mime-Util.

The first gave me memory exceptions, the second doesn't close its streams off properly. I was just wondering if anyone else had a method/library that they used and worked correctly?

Answer

Chris Mowforth picture Chris Mowforth · Jan 23, 2012

In Java 7 you can now just use Files.probeContentType(path).