Java tutorial
//package com.java2s; public class Main { /** * Returns true if the given filePath refers a text file. */ public static boolean isTextFile(String filePath) { String contentType = getContentTypeForFilePath(filePath); return contentType.startsWith("text/"); } /** * Returns the content type for the given filePath. */ public static String getContentTypeForFilePath(String filePath) { filePath = filePath.toLowerCase(); if (filePath.endsWith(".gif")) { return "image/gif"; } if (filePath.endsWith(".jpg") || filePath.endsWith(".jpeg")) { return "image/jpeg"; } if (filePath.endsWith(".png")) { return "image/png"; } if (filePath.endsWith(".apk")) { return "application/vnd.android.package-archive; charset=utf-8"; } if (filePath.endsWith(".zip")) { return "application/zip; charset=utf-8"; } if (filePath.endsWith(".keystore")) { return "application/octet-stream"; } // default return "text/plain; charset=utf-8"; } }