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

Comments

Popular posts from this blog

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

Escape HTML and XML in Java

Sort a HashMap based on Keys or Values