Here you can find the source of getImageType(File file)
public static String getImageType(File file)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.HashMap; public class Main { private static HashMap<String, String> custommimetypes = new HashMap<String, String>(); public static String getImageType(File file) { return getFileType(file).split("/")[1]; }/*from ww w .ja va2 s. c o m*/ public static String getFileType(File file) { String extension = getExtension(file.getName()); if (custommimetypes.containsKey(extension)) return custommimetypes.get(extension); try { String content = Files.probeContentType(file.toPath()); if (content != null) return content; else return "application/octet-stream"; } catch (IOException e) { e.printStackTrace(); } return "text/plain"; } public static String getExtension(String filename) { if (filename.contains(".")) { return filename.substring(filename.lastIndexOf(".") + 1).toLowerCase(); } else { return ""; } } }