public String getContentType(File file) {
        String fileName = file.getName();
        String contentType;
        if (fileName.endsWith(".htm") || fileName.endsWith(".html"))
            contentType = "text/html";
        else if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg"))
            contentType = "image/jpeg";
        else if (fileName.endsWith(".png"))
            contentType = "image/png";
        else if (fileName.endsWith(".gif"))
            contentType = "image/gif";
        else if (fileName.endsWith(".pdf"))
            contentType = "application/pdf";
        else if (fileName.endsWith(".ico"))
            contentType = "image/x-icon";
        else
            contentType = "text/plain";
        return contentType;
    }