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