gpt4 book ai didi

java - 为什么 MimetypesFileTypeMap 总是为 PNG 文件返回 "application/octet-stream"?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:16:03 25 4
gpt4 key购买 nike

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

对于字符串“image.png”,它总是返回“application/octect-stream”……它不应该返回类似“image/png”的东西吗?

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

最佳答案

参见 javax.activation.MimetypesFileTypeMap 的 Javadocs .该方法查找名为 .mime.types 的文件按一定顺序:

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:

  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 :

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.

关于java - 为什么 MimetypesFileTypeMap 总是为 PNG 文件返回 "application/octet-stream"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34165873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com