为什么Files.probeContentType返回null [英] why does Files.probeContentType return null

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

问题描述

我在mac上使用java se7,oracle预览。

i am using java se7 on mac, the oracle preview.

我的问题是Files.probeContentType返回null ...它是否有可能到期到了se7的早期状态为mac?
我的代码:

My problem is that "Files.probeContentType" returns null...is it possible that its due to the early status of se7 for mac? My code:

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

"/Users/admin/Desktop/temp/q12/formulare/Bildschirmfoto 2012-09-11 um 17.57.59.png"

in eclipse中的调试模式,如果我将鼠标悬停在文件文件路径= Unis-path(id:145)上面为红色

and in debug mode in eclipse if i hover above File "file path = Unis-path(id:145)" is red

推荐答案

我已经再次向oracle报告了这个bug,希望他们能够向后移动jdk8解决方案(我没有太多希望,但你永远不知道)。

I have reported the bug to oracle again, hoping they will backport the jdk8 solution (I don't have much hope but you never know).

在此期间你可以使用我自己的FileTypeDetector的backport可以在 https://github.com/jeantil/jdk7-mimeutils 上找到maven项目打包到jar,可以添加到类路径以启用mime类型检测。我还提供了一个mime.types文件放在您的主文件夹中,以便检测正常工作。我从某个版本的apache中提取了mime.types文件,所以它非常完整。

In the meantime you can use my own backport of the FileTypeDetector available at https://github.com/jeantil/jdk7-mimeutils the maven project packages to a jar which can be added to your classpath to enable mime type detection. I also provide a mime.types file to put in your home folder for the detection to work correctly. I extracted the mime.types file from some version of apache so it's pretty complete.

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

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