java 7中可以判断文件的contenttype了

时间:2022-12-05 08:59:08


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方法了.


相关文章