Java Path File Mime Type nio getMimeType(Path path)

Here you can find the source of getMimeType(Path path)

Description

Gets a file's content type.

License

Open Source License

Parameter

Parameter Description
path the path to the file to probe.

Exception

Parameter Description
IOException if something goes wrong.

Return

the file content type.

Declaration

public static String getMimeType(Path path) throws IOException 

Method Source Code


//package com.java2s;
import java.io.IOException;

import java.nio.file.*;

public class Main {
    /**//from  w  ww. j  a  va  2 s  . c  o m
     * Gets a file's content type.
     *
     * @param path the path to the file to probe.
     * @return the file content type.
     * @throws IOException if something goes wrong.
     */
    public static String getMimeType(Path path) throws IOException {
        // An implementation using "Java Service Provider Interface (SPI)" is
        // registered in /META-INF/services/java.nio.file.spi.FileTypeDetector,
        // improving the standard default NIO implementation with the Apache Tika API.
        return Files.probeContentType(path);
    }
}

Related

  1. getMimeType(String absolutePath)