tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Jodd > Utils > How to get MIME type by extension

How to get MIME type by extension 

Jodd is an open-source java library with lot of reusable components and feature rich utilities. This requires the library jodd-3.3.2.jar to be in classpath. The following example shows how to get the MIME type for the given extension using MimeTypes.getMimeType() API. It returns application/octet-stream type if there is no matching extension.

File Name  :  
com/bethecoder/tutorials/jodd/utils/MimeTypeTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jodd.utils;

import jodd.util.MimeTypes;

public class MimeTypeTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    System.out.println(MimeTypes.getMimeType("pdf"));
    System.out.println(MimeTypes.getMimeType("doc"));
    System.out.println(MimeTypes.getMimeType("swf"));
    System.out.println(MimeTypes.getMimeType("jpg"));
    System.out.println(MimeTypes.getMimeType("text"));
    System.out.println(MimeTypes.getMimeType("json"));
    System.out.println(MimeTypes.getMimeType("jar"));
    System.out.println(MimeTypes.getMimeType("ABCD"));
  }

}
   

It gives the following output,
application/pdf
application/msword
application/x-shockwave-flash
image/jpeg
application/octet-stream
application/json
application/java-archive
application/octet-stream


                    Print

   



Books Recommendation

 
 
bl  br