我只是想知道大多数人如何从Java中的文件中获取mime类型?到目前为止,我已经尝试了两个工具:JMimeMagic&Mime-Util.
第一个给了我内存异常,第二个没有正确关闭它的流.我只是想知道是否有其他人有他们使用和正常工作的方法/库?
我在mac上使用java se7,oracle预览.
我的问题是"Files.probeContentType"返回null ...是否有可能是因为se7的早期状态为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);
}
Run Code Online (Sandbox Code Playgroud)
该文件的名称是:
"/ Users/admin/Desktop/temp/q12/formulare/Bildschirmfoto 2012-09-11 um 17.57.59.png"
并且在eclipse中的调试模式下,如果我将鼠标悬停在文件"文件路径= Unis-path(id:145)"上方为红色