Lee Theobald Lee Theobald - 1 year ago 57
Java Question

Getting A File's Mime Type In Java

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


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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download