Here you can find the source of getMimeType(String fileName)
Parameter | Description |
---|---|
fileName | The name of the file to find a MIME type for. |
private static String getMimeType(String fileName)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.net.FileNameMap; import java.net.URLConnection; public class Main { /**/*from ww w . j a va 2 s.c o m*/ * Attempts to determine the MIME type of the specified file. If no type is detected, falls back * to <code>application/octet-stream</code>. * * @param fileName The name of the file to find a MIME type for. * @return The MIME type to use for uploading this file. * @see FileNameMap#getContentTypeFor(String) */ private static String getMimeType(String fileName) { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor(fileName); if (mimeType != null) return mimeType; return "application/octet-stream"; } }