Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;
import java.util.Locale;

import android.webkit.MimeTypeMap;

public class Main {
    public static String getMIMETypeFromFileName(String fileName) {
        if (fileName == null) {
            return null;
        }
        String extension = getExtensionFromFileName(fileName);
        if (extension == null) {
            return null;
        }
        return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    }

    public static String getExtensionFromFileName(String fileName) {
        int slash = fileName.lastIndexOf(File.separatorChar);
        int dot = fileName.lastIndexOf('.');
        if (slash >= dot) {
            return null;
        }
        String extension = fileName.substring(dot + 1).toLowerCase(Locale.ENGLISH);
        return extension;
    }
}