java 7中可以判断文件的contenttype了,例子如下:
Path path = Paths.get("D:/Downloads/java.txt");
String contentType = null;
try {
contentType = Files.probeContentType(path);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("File content type is : " + contentType);
}
就是使用Files.probeContentType方法了.