Skip to content

Most visited

Recently visited



public abstract class FileTypeDetector
extends Object

   ↳ java.nio.file.spi.FileTypeDetector

A file type detector for probing a file to guess its file type.

A file type detector is a concrete implementation of this class, has a zero-argument constructor, and implements the abstract methods specified below.

The means by which a file type detector determines the file type is highly implementation specific. A simple implementation might examine the file extension (a convention used in some platforms) and map it to a file type. In other cases, the file type may be stored as a file attribute or the bytes in a file may be examined to guess its file type.

See also:


Protected constructors


Initializes a new instance of this class.

Public methods

abstract String probeContentType(Path path)

Probes the given file to guess its content type.

Inherited methods

From class java.lang.Object

Protected constructors


added in API level 26
FileTypeDetector ()

Initializes a new instance of this class.

SecurityException If a security manager has been installed and it denies RuntimePermission("fileTypeDetector")

Public methods


added in API level 26
String probeContentType (Path path)

Probes the given file to guess its content type.

The means by which this method determines the file type is highly implementation specific. It may simply examine the file name, it may use a file attribute, or it may examines bytes in the file.

The probe result is the string form of the value of a Multipurpose Internet Mail Extension (MIME) content type as defined by RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies. The string must be parsable according to the grammar in the RFC 2045.

path Path: the path to the file to probe

String The content type or null if the file type is not recognized

IOException An I/O error occurs
SecurityException If the implementation requires to access the file, and a security manager is installed, and it denies an unspecified permission required by a file system provider implementation. If the file reference is associated with the default file system provider then the checkRead(String) method is invoked to check read access to the file.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)