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


Popular posts from this blog

Get Remote IP Address In Axis SOAP Server

Connect via SSH without a password from MacOS to Linux with an SSHKEY