一个文件如果改成临时文件或者想从文件取得MIME type还是比较麻烦的,目前找到一个可用的方法分享给大家
String pathname = "/tmp/1";
File file = new File(pathname);
InputStream is = new BufferedInputStream(new FileInputStream(file));
String mimeType = URLConnection.guessContentTypeFromStream(is);
System.out.println(mimeType);