【发布时间】:2013-02-15 19:09:12
【问题描述】:
此方法应检查文件是否为 MIME 类型。为了实现这个目标,我正在使用方法probeContentType()。
然而,也许是决定相同问题的另一种方式。还有哪些其他选择(如果有的话)?
代码:
class ProbeContentTypeCheker implements Checker {
@Override
public boolean check(File fileCheck) {
try {
Path filePath = FileSystems.getDefault().getPath(
fileCheck.getAbsolutePath());
if ((Files.probeContentType(filePath) != null)) {
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
问题:
- 还有其他方法可以检查文件中的 MIME 类型吗?
【问题讨论】:
标签: java mime-types