Partager via


Files.ProbeContentType(IPath) Method

Definition

Probes the content type of a file.

[Android.Runtime.Register("probeContentType", "(Ljava/nio/file/Path;)Ljava/lang/String;", "", ApiSince=26)]
public static string? ProbeContentType (Java.Nio.FileNio.IPath? path);
[<Android.Runtime.Register("probeContentType", "(Ljava/nio/file/Path;)Ljava/lang/String;", "", ApiSince=26)>]
static member ProbeContentType : Java.Nio.FileNio.IPath -> string

Parameters

path
IPath

the path to the file to probe

Returns

The content type of the file, or null if the content type cannot be determined

Attributes

Remarks

Probes the content type of a file.

This method uses the installed FileTypeDetector implementations to probe the given file to determine its content type. Each file type detector's FileTypeDetector#probeContentType probeContentType is invoked, in turn, to probe the file type. If the file is recognized then the content type is returned. If the file is not recognized by any of the installed file type detectors then a system-default file type detector is invoked to guess the content type.

A given invocation of the Java virtual machine maintains a system-wide list of file type detectors. Installed file type detectors are loaded using the service-provider loading facility defined by the ServiceLoader class. Installed file type detectors are loaded using the system class loader. If the system class loader cannot be found then the extension class loader is used; If the extension class loader cannot be found then the bootstrap class loader is used. File type detectors are typically installed by placing them in a JAR file on the application class path or in the extension directory, the JAR file contains a provider-configuration file named java.nio.file.spi.FileTypeDetector in the resource directory META-INF/services, and the file lists one or more fully-qualified names of concrete subclass of FileTypeDetector that have a zero argument constructor. If the process of locating or instantiating the installed file type detectors fails then an unspecified error is thrown. The ordering that installed providers are located is implementation specific.

The return value of this method is the string form of the value of a Multipurpose Internet Mail Extension (MIME) content type as defined by RFC&nbsp;2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodieshttp://www.ietf.org/rfc/rfc2045.txt. The string is guaranteed to be parsable according to the grammar in the RFC.

Java documentation for java.nio.file.Files.probeContentType(java.nio.file.Path).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to