public class MimetypesFileTypeMap extends FileTypeMap
This class extends FileTypeMap and provides data typing of files
via their file extension. It uses the .mime.types format.
MIME types file search order:
The MimetypesFileTypeMap looks in various places in the user's system for MIME types file entries. When requests are made to search for MIME types in the MimetypesFileTypeMap, it searches MIME types files in the following order:
.mime.types in the user's home directory.
/lib/mime.types.
META-INF/mime.types.
META-INF/mimetypes.default
MIME types file format:
# comments begin with a '#'
# the format is <mime type> <space separated file extensions>
# for example:
text/plain txt text TXT
# this would map file.txt, file.text, and file.TXT to
# the mime type "text/plain"
type/subtype ext1 ext2 ... or type=type/subtype desc="description of type" exts=ext1,ext2,...
| 限定符和类型 | 类和说明 |
|---|---|
class |
MimetypesFileTypeMap.MimeTypeFile |
| 构造器和说明 |
|---|
MimetypesFileTypeMap(InputStream is)
Construct a MimetypesFileTypeMap with programmatic entries added from the
InputStream.
|
MimetypesFileTypeMap(String mimeTypeFileName)
Construct a MimetypesFileTypeMap with programmatic entries added from the
named file.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addMimeTypes(String mime_types)
Prepend the MIME type values to the registry.
|
String |
getContentType(File f)
Return the MIME type of the file object.
|
String |
getContentType(String filename)
Return the MIME type based on the specified file name.
|
String |
getContentTypeByExt(String extension)
通过文件扩展名获取ContentType
|
String[] |
getExtensions(String mimeType)
根据文件的mimeType或者可用的文件扩展名
|
static MimetypesFileTypeMap |
getInstance()
获取单例对象
|
getDefaultFileTypeMap, setDefaultFileTypeMappublic MimetypesFileTypeMap(String mimeTypeFileName) throws IOException
mimeTypeFileName - the file nameIOExceptionpublic MimetypesFileTypeMap(InputStream is)
is - the input stream to read frompublic static MimetypesFileTypeMap getInstance()
public void addMimeTypes(String mime_types)
mime_types - A .mime.types formatted string of entries.public String getContentType(File f)
getContentType(f.getName()).getContentType 在类中 FileTypeMapf - the filepublic String getContentType(String filename)
getContentType 在类中 FileTypeMapfilename - the file nameCopyright © 2016. All rights reserved.