- // url = file path or whatever suitable URL you want.
- public static String getMimeType(String url)
- {
- String type = null;
- String extension = MimeTypeMap.getFileExtensionFromUrl(url);
- if (extension != null) {
- MimeTypeMap mime = MimeTypeMap.getSingleton();
- type = mime.getMimeTypeFromExtension(extension);
- }
- return type;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0412201411184.html
来源: http://www.codesnippet.cn/detail/0412201411184.html