Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.webkit.MimeTypeMap;
import java.io.File;

public class Main {
    public static String getMIMETypeFromUrl(final File file, final String defaultValue) {

        MimeTypeMap mime = MimeTypeMap.getSingleton();
        int index = file.getName().lastIndexOf('.') + 1;
        String ext = file.getName().substring(index).toLowerCase();
        final String mimeType = mime.getMimeTypeFromExtension(ext);

        if (mimeType != null) {
            return mimeType;
        }

        return defaultValue;
    }
}