JAVA WEB 判断上传的文件是否是图片
1个回答
展开全部
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;
}
写一个识别文件类型的方法:
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;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询