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