Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import android.webkit.MimeTypeMap; public class Main { public static String getFileMimeType(File file) { String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(getExtension(file)); if (type == null) return "*/*"; return type; } /** * Gets the extension of a file name, like "png" or "jpg". * * @param uri * @return Extension excluding the dot("."); "" if there is no extension; * null if uri was null. */ public static String getExtension(String uri) { if (uri == null) { return null; } int dot = uri.lastIndexOf("."); if (dot >= 0) { return uri.substring(dot + 1); } else { // No extension. return ""; } } public static String getExtension(File file) { return getExtension(file.getName()); } }