Java tutorial
//package com.java2s; import java.net.FileNameMap; import java.net.URLConnection; public class Main { public static String getFileType(String fn, String defaultType) { FileNameMap fNameMap = URLConnection.getFileNameMap(); String type = fNameMap.getContentTypeFor(fn); return type == null ? defaultType : type; } public static String getFileType(String fn) { return getFileType(fn, "application/octet-stream"); } }