java - 为什么 Files.probeContentType 返回 null

标签 java macos

我在 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/

相关文章:

java - 有没有办法在java中获取WordprocessingML剪贴板内容?

objective-c - 使用 Cocoa 监控苹果 "System Events"

macos - Qt 5.4 OS X 如何在 QMenu 和 QToolBar 中使用 QAction,但仅在 QToolbar 中显示图标

excel - 如何使用 Applescript 循环遍历 Excel 中的选定单元格?

swing - Switch 语句有问题吗?

java - Android ui元素动画

java - org.hibernate.AnnotationException : A Foreign key refering X from Y has the wrong number of column. 应该是 2

java - Spring规范的谓词应该是静态的吗?

xcode - 在 SwiftUI macOS 应用程序的主菜单中启用菜单项?

macos - OSX 终端选项卡/Windows