Here you can find the source of getContentType(final String filename)
Parameter | Description |
---|---|
filename | a parameter |
public static String getContentType(final String filename)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.FileNameMap; import java.net.URLConnection; public class Main { /**/*from ww w . j av a 2s . c o m*/ * Return the contentType for a given filename if it is defined inside the JVM * * @param filename * @return the content type */ public static String getContentType(final String filename) { FileNameMap mapNew = URLConnection.getFileNameMap(); String temp = mapNew.getContentTypeFor("." + getExtension(filename)); return (temp == null) ? "application/octet-stream" : temp; } public static String getExtension(final File f) { return getExtension(f.getName()); } public static String getExtension(final String f) { return f.substring(f.lastIndexOf('.') + 1); } }