Java tutorial
//package com.java2s; import java.net.FileNameMap; import java.net.URLConnection; public class Main { public static String getMimeType(String filename) { FileNameMap filenameMap = URLConnection.getFileNameMap(); String contentTypeFor = filenameMap.getContentTypeFor(filename); if (contentTypeFor == null) { contentTypeFor = "application/octet-stream"; } return contentTypeFor; } }