Java File Mime Type getMimeType(String fileName)

Here you can find the source of getMimeType(String fileName)

Description

get Mime Type

License

Apache License

Declaration

public static String getMimeType(String fileName) 

Method Source Code

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

import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
    public static String getMimeType(String fileName) {
        try {//w w  w  .ja v  a2  s .  c  o  m
            return Files.probeContentType(Paths.get(fileName));
        } catch (IOException e) {
            return "application/octet-stream";
        }
        /*
         * Collection types = MimeUtil.getMimeTypes(fileName); return
         * MimeUtil2.getMostSpecificMimeType(types).toString();
         */
    }
}

Related

  1. detectFileType(String location)
  2. getFileType(String fileName)
  3. getImageType(File file)
  4. getMime(File file)
  5. getMimeType(File file)
  6. getType(File file)
  7. isMP3(File file)
  8. isValidImage(File file)