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

Read and Write Files in Java

Install Mac OS on windows laptop