android典型代码系列(二十一)------根据文件后缀名获得对应的MIME类型
来源:互联网 发布:手机淘宝店如何招代理 编辑:程序博客网 时间:2024/05/16 10:50
21_根据文件后缀名获得对应的MIME类型1 :
import java.io.File;public class FileType { /** * 根据文件后缀名获得对应的MIME类型。 * * @param file */ public String getMIMEType(File file) { String type = "*/*"; String fName = file.getName(); // 获取后缀名前的分隔符"."在fName中的位置。 int dotIndex = fName.lastIndexOf("."); if (dotIndex < 0) { return type; } /* 获取文件的后缀名 */ String end = fName.substring(dotIndex, fName.length()).toLowerCase(); if (end == "") return type; // 在MIME和文件类型的匹配表中找到对应的MIME类型。 for (int i = 0; i < MIME_MapTable.length; i++) { if (end.equals(MIME_MapTable[i][0])) type = MIME_MapTable[i][1]; } return type; } private final String[][] MIME_MapTable = { // {后缀名,MIME类型} { ".3gp", "video/3gpp" }, { ".apk", "application/vnd.android.package-archive" }, { ".asf", "video/x-ms-asf" }, { ".avi", "video/x-msvideo" }, { ".bin", "application/octet-stream" }, { ".bmp", "image/bmp" }, { ".c", "text/plain" }, { ".class", "application/octet-stream" }, { ".conf", "text/plain" }, { ".cpp", "text/plain" }, { ".doc", "application/msword" }, { ".exe", "application/octet-stream" }, { ".gif", "image/gif" }, { ".gtar", "application/x-gtar" }, { ".gz", "application/x-gzip" }, { ".h", "text/plain" }, { ".htm", "text/html" }, { ".html", "text/html" }, { ".jar", "application/java-archive" }, { ".java", "text/plain" }, { ".jpeg", "image/jpeg" }, { ".jpg", "image/jpeg" }, { ".js", "application/x-javascript" }, { ".log", "text/plain" }, { ".m3u", "audio/x-mpegurl" }, { ".m4a", "audio/mp4a-latm" }, { ".m4b", "audio/mp4a-latm" }, { ".m4p", "audio/mp4a-latm" }, { ".m4u", "video/vnd.mpegurl" }, { ".m4v", "video/x-m4v" }, { ".mov", "video/quicktime" }, { ".mp2", "audio/x-mpeg" }, { ".mp3", "audio/x-mpeg" }, { ".mp4", "video/mp4" }, { ".mpc", "application/vnd.mpohun.certificate" }, { ".mpe", "video/mpeg" }, { ".mpeg", "video/mpeg" }, { ".mpg", "video/mpeg" }, { ".mpg4", "video/mp4" }, { ".mpga", "audio/mpeg" }, { ".msg", "application/vnd.ms-outlook" }, { ".ogg", "audio/ogg" }, { ".pdf", "application/pdf" }, { ".png", "image/png" }, { ".pps", "application/vnd.ms-powerpoint" }, { ".ppt", "application/vnd.ms-powerpoint" }, { ".prop", "text/plain" }, { ".rar", "application/x-rar-compressed" }, { ".rc", "text/plain" }, { ".rmvb", "audio/x-pn-realaudio" }, { ".rtf", "application/rtf" }, { ".sh", "text/plain" }, { ".tar", "application/x-tar" }, { ".tgz", "application/x-compressed" }, { ".txt", "text/plain" }, { ".wav", "audio/x-wav" }, { ".wma", "audio/x-ms-wma" }, { ".wmv", "audio/x-ms-wmv" }, { ".wps", "application/vnd.ms-works" }, { ".xml", "text/xml" }, { ".xml", "text/plain" }, { ".z", "application/x-compress" }, { ".zip", "application/zip" }, { "", "*/*" } };}
0 0
- android典型代码系列(二十一)------根据文件后缀名获得对应的MIME类型
- java根据文件后缀名获得对应的MIME类型
- Android MIME类型与文件后缀名匹配部分
- 常用的文件对应的MIME类型
- 常用的文件对应的MIME类型
- 常用的文件对应的MIME类型
- 常用的文件对应MIME类型
- android典型代码系列(二十五)------popupwindow的使用
- android典型代码系列(二十六)------App widget的使用
- android典型代码系列(二十八)------通话记录的操作
- 常见文件后缀名和Content-type/mime type对应关系
- android典型代码系列(十一)------判断某个应用程序是 不是三方的应用程序
- iis7如何添加mime类型支持所有后缀名文件的方法
- iis7如何添加mime类型支持所有后缀名文件的方法
- php 用mime type 获得临时文件的后缀名
- android典型代码系列(十三)------通过反射获得未暴露的方法
- android 文件的mime类型大全
- [Android] 获取文件的MIME类型
- CentOS-7下安装apache
- CRITICAL_SECTION http://blog.csdn.net/leowangzi/article/details/6572650
- hdu 1257
- Nginx的信号控制
- C++内存对齐笔记
- android典型代码系列(二十一)------根据文件后缀名获得对应的MIME类型
- LibGDX_1.3: Desktop 环境搭建:创建 Eclipse User Library,一劳永逸
- 剑指offer系列之八:跳台阶问题
- MyBatis入门学习教程
- 线性表
- python基础教程共60课-第4课输入
- eclipse/ADT 安装Gradle
- ORCAD层次化设计遇到Cannot descend from a schematic page that is not contained within the hierarchy
- 电子或通信领域当前的主流技术及其社会需求调查报告