Here you can find the source of getContentType(String name)
Parameter | Description |
---|---|
name | the name of a file |
public static String getContentType(String name)
//package com.java2s; import java.net.FileNameMap; import java.net.URLConnection; import java.util.Properties; public class Main { /** the local content type map */ private static Properties localFileNameMap; /**/* w ww.j av a 2s . c o m*/ * Gets the content type for the specified filename. * * @param name the name of a file * @return a MIME type, or application/octet-stream if one can't be found */ public static String getContentType(String name) { String contentType; FileNameMap fileNameMap = URLConnection.getFileNameMap(); contentType = fileNameMap.getContentTypeFor(name); if (contentType == null) { int index = name.lastIndexOf("."); if (index > -1) { contentType = localFileNameMap.getProperty(name.substring(index)); } } return contentType; } }