Friday, February 27, 2009

Get MimeType of A File

Use activation.jar to access javax.activation API.

File file = new File("foo.jpg");
String mimeType = new MimetypesFileTypeMap().getContentType(file)); // image/jpeg

alternatively , you can use filename to detech the mime type :
String mimeType = new MimetypesFileTypeMap().getContentType("foo.jpg")); // image/jpeg

No comments: