现在的位置: 首页 > 综合 > 正文

Java如何获取文件的内容类型?例如:image/gif

2016年12月02日 ⁄ 综合 ⁄ 共 304字 ⁄ 字号 评论关闭
网站上传文件后,如果是图片,都要对文件进行处理,压缩、缩放之类的。
 import java.nio.file.*;
//如果是图片文件,则执行缩放处理
			 Path source = Paths.get(newFilePath);
			 String contentType = Files.probeContentType(source);
			 if (contentType.startsWith("image")){
					String thumbPath = this.getImgAbsolutePath(request, "thumb");
					ImageUtils.resize(newFilePath, thumbPath, 94, 222, true);
			 }

抱歉!评论已关闭.