集册 Java实例教程 返回给定mime的默认扩展名

返回给定mime的默认扩展名

欢马劈雪     最近更新时间:2020-01-02 10:19:05

688
返回给定mime类型的默认扩展名,如果mime type未知,则返回空字符串。


//package com.nowjava;/* 来 自 时代Java公众号 - nowjava.com*/


public class Main {

    /**

     * Returns a default extension for a given mime-type, or an 

     * empty string if the mimetype is unknown.

     * @param type

     * @return extension

     */

    public static String getExtension(String type) {

        if (type.equals("application/msword"))

            return "doc";

        if (type.equals("application/pdf"))

            return "pdf";

        if (type.equals("application/vnd.oasis.opendocument.text"))

            return "odt";

        if (type.equals("application/vnd.sun.xml.calc"))

            return "sxc";

        if (type.equals("application/x-javascript")

                || type.equals("text/javascript"))

            return "js";
            /* 
             来自 
            *nowjava.com*/

        if (type.equals("application/x-xpinstall"))

            return "xpi";

        if (type.equals("application/zip"))

            return "zip";

        if (type.equals("image/bmp"))

            return "bmp";

        if (type.equals("image/gif"))

            return "gif";

        if (type.equals("image/tiff"))

            return "tif";

        if (type.equals("image/jpeg"))

            return "jpg";

        if (type.equals("image/png"))

            return "png";

        if (type.equals("text/css"))

            return "css";

        if (type.equals("text/html")

                || type.equals("application/xhtml+xml"))

            return "html";

        if (type.equals("text/plain"))

            return "txt";

        if (type.equals(
展开阅读全文