Java tutorial
//package com.java2s; public class Main { public static String getMIMEType(String file) { String type = ""; String end = file.substring(file.lastIndexOf(".") + 1, file.length()).toLowerCase(); if (end.equals("apk")) { return "application/vnd.android.package-archive"; } else if (end.equals("mp4") || end.equals("avi") || end.equals("3gp") || end.equals("rmvb")) { type = "video"; } else if (end.equals("m4a") || end.equals("mp3") || end.equals("mid") || end.equals("xmf") || end.equals("ogg") || end.equals("wav")) { type = "audio"; } else if (end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg") || end.equals("bmp")) { type = "image"; } else if (end.equals("txt") || end.equals("log")) { type = "text"; } else { type = "*"; } type += "/*"; return type; } }