且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-08-19 17:34:07

网站上传文件后,如果是图片,都要对文件进行处理,压缩、缩放之类的。

 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);
			 }