Friday, 14 June 2013

Find Mime Type Of a file in java

import java.io.File;

import javax.activation.MimetypesFileTypeMap;


public class TestMimeType {
public static void main(String[] args) {
 String fileName = "C://bunny.mp4";
 MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();

 // only by file name
 String mimeType = mimeTypesMap.getContentType(fileName);

 // or by actual File instance
 File file = new File(fileName);
 mimeType = mimeTypesMap.getContentType(file);
 
 System.out.println(mimeType);
}
}


0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...