How to get a file’s Media Type (MIME type)? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to get a file’s Media Type (MIME type)? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

How do you get a Media Type (MIME type) from a file using Java? So far I’ve tried JMimeMagic & Mime-Util. The first gave me memory exceptions, the second doesn’t close its streams properly.

How would you probe the file to determine its actual type (not merely based on the extension)?

Answer

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

We are here to answer your question about How to get a file’s Media Type (MIME type)? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji