为什么MimetypesFileTypeMap总是返回"application/octet-stream"?为PNG文件? [英] Why does MimetypesFileTypeMap always return "application/octet-stream" for PNG file?

查看:733
本文介绍了为什么MimetypesFileTypeMap总是返回"application/octet-stream"?为PNG文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javax.activation.MimetypesFileTypeMap来获取内容类型.

I'm trying to use javax.activation.MimetypesFileTypeMap to get the content type.

对于字符串"image.png",它总是返回"application/octect-stream" ...它不应该返回诸如"image/png"之类的东西吗?

For the string "image.png" it always returns "application/octect-stream" ... shouldn't it return something like "image/png" ?

javax.activation.MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType("image.png");

推荐答案

请参见

MIME类型文件搜索顺序:

MimetypesFileTypeMap在用户系统的各个位置查找MIME类型文件条目.当请求在MimetypesFileTypeMap中搜索MIME类型时,它将按以下顺序搜索MIME类型文件:

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:

  1. 以编程方式将条目添加到MimetypesFileTypeMap实例.
  2. 用户主目录中的文件.mime.types.
  3. 文件<java.home>/lib/mime.types.
  4. 名为META-INF/mime.types的文件或资源.
  5. 名为META-INF/mimetypes.default的文件或资源(通常仅在activation.jar文件中找到).
  1. Programmatically added entries to the MimetypesFileTypeMap instance.
  2. The file .mime.types in the user's home directory.
  3. The file <java.home>/lib/mime.types.
  4. The file or resources named META-INF/mime.types.
  5. The file or resource named META-INF/mimetypes.default (usually found only in the activation.jar file).

如果未找到文件,则getContentType方法返回application/octet-stream:

If no file is found, getContentType method returns application/octet-stream:

根据指定的文件名返回MIME类型.如上所述,在 MIME类型文件搜索顺序下搜索MIME类型条目.如果未找到任何条目,则返回"application/octet-stream"类型.

Return the MIME type based on the specified file name. The MIME type entries are searched as described above under MIME types file search order. If no entry is found, the type "application/octet-stream" is returned.

这篇关于为什么MimetypesFileTypeMap总是返回"application/octet-stream"?为PNG文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆