[code="java"]
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);
}
[/code]
就是使用Files.probeContentType方法了.