我在 mac 上使用 java se7,oracle 预览。
我的问题是“Files.probeContentType”返回空值...这是否可能是由于 se7 for mac 的早期状态? 我的代码:
if(directory == null) return;
String content = null;
try {
content = Files.probeContentType(directory.toPath());
} catch (IOException e) {
JOptionPane.showMessageDialog(main, e.toString());
return;
}
if(content == null)
{
return;
}
else if(content.contains("image"))
{
main.pctviewer.setImage(directory);
}
文件名是:
"/Users/admin/Desktop/temp/q12/formulare/Bildschirmfoto 2012-09-11 um 17.57.59.png"
如果我将鼠标悬停在文件“file path = Unis-path(id:145)”上方,则在 Eclipse 中处于 Debug模式是红色的
最佳答案
我已经再次向 oracle 报告了这个错误,希望他们能够向后移植 jdk8 解决方案(我没有太大希望,但你永远不知道)。
与此同时,您可以使用我自己的 FileTypeDetector backport,网址为 https://github.com/jeantil/jdk7-mimeutils。 maven 项目打包到一个 jar 中,可以将其添加到类路径中以启用 mime 类型检测。我还提供了一个 mime.types 文件放在您的主文件夹中,以便检测正常工作。我从某个版本的 apache 中提取了 mime.types 文件,所以它非常完整。
关于java - 为什么 Files.probeContentType 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12407479/