在OpenJDK 11上Files.probeContentType()返回null [英] Files.probeContentType() returns null on OpenJDK 11

查看:122
本文介绍了在OpenJDK 11上Files.probeContentType()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OpenJDK 11上,似乎 Files.probeContentType()返回文件的 null (其中MIME类型未由其文件名指示).在OpenJDK 8上工作(在Linux x64上).是什么原因呢?

It seems that Files.probeContentType() returns null for a file (where the MIME type is not indicated by its file name) on OpenJDK 11, while it was working on OpenJDK 8 (on Linux x64). What is the reason for that?

注意:可能适用于以名称表示类型的文件,例如"test.pdf"将产生"application/pdf",但是将文件重命名为"test".将产生 null .

Note: It may work for files where the type is indicated by its name, e.g., "test.pdf" will produce "application/pdf", but renaming the file to "test" will produce null.

推荐答案

文件类型检测在很大程度上是特定于平台的,因此不被认为是可靠的.例如, GnomeFileTypeDetector 在JDK 8中可用,但仅在Linux系统上可用.

File type detection is largely platform-specific and was not considered reliable. For instance, GnomeFileTypeDetector was available in JDK 8, but only working on Linux systems.

OpenJDK开发人员已决定从JDK中删除 GnomeFileTypeDetector MagicFileTypeDetector (已在JDK 9中删除),请参见这里.

The OpenJDK developers have decided to remove both GnomeFileTypeDetector and MagicFileTypeDetector from the JDK (already in JDK 9), see OpenJDK bug tracker and here.

可用的检测器 MimeTypesFileTypeDetector (在Linux上)或 RegistryFileTypeDetector 在Windows上仅实现从文件扩展名到MIME类型的映射,但不检查文件的实际内容.

Available detectors MimeTypesFileTypeDetector (on Linux) or RegistryFileTypeDetector on Windows simply implement a mapping from file name extensions to MIME types, but do not inspect the actual contents of files.

(注意:所有检测器实现都在软件包 sun.nio.fs 中找到(或未找到).)

(Note: all detector implementations are found (or not) in package sun.nio.fs.)

这篇关于在OpenJDK 11上Files.probeContentType()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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