<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.4.0</version>
</dependency>
/**
* @author Yaxin
* @date 2022/6/8 21:41
*/
public class FileUtil {
static Tika tika = new Tika();
static final String IMG = "image";
public static String getMimeType(File file) {
try {
return tika.detect(file);
} catch (IOException e) {
e.printStackTrace();
}
return "Unidentifiable";
}
public static boolean isImg(File file) {
return getMimeType(file).equals(IMG);
}
}
PS:
网上某些论坛一篇博文转来转去真是误人子弟