java web识别文件的类型是通过文件后缀识别的。
写一个识别文件类型的方法:
public String identifyFileTypeUsingFilesProbeContentType(final String fileName) {
String fileType = "Undetermined";
final File file = new File(fileName);
try {
fileType = Files.probeContentType(file.toPath());
} catch (IOException ioException) {
out.println( "ERROR: Unable to determine file type for " + fileName + " due to exception " + ioException);
}
return fileType;
}