Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

java.nio.file.spi.FileTypeDetector Class in Java

  • Last Updated : 13 Apr, 2021

java.nio.file.spi.FileTypeDetector Class extends java.lang.Object Class. FileTypeDetector Class contain method to know about the content type of given file.

Class declaration:

public abstract class FileTypeDetector
extends Object


protected FileTypeDetector()It is used the creation of a new object of FileTypeDetector class. 


probeContentType(Path path)It is used to guess the content type of the given file. 

abstract String probeContentType(Path path): It is used to guess the content type of the given file. To know the content type of the file this method may examine the filename, use file attribute, or even examine the bytes in the file. The way of examination of file solely depends on the implementation.


  • path – the path of the file whose content type is to be guessed

Returns: The content type of the given file.If the file type is not recognized it returns null.


  • IOException – if an I/O error occurs
  • SecurityException – If the security manager denies access to the given file.


// Java program to illustrate use of probeContentType()
// method of FileTypeDetector class
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class GFG {
    public static void main(String[] args)
        try {
            // create object of Path
            Path path = (Path)Paths.get("/usr", "local",
                                        "bin", "file.txt");
            // Print content type of the file present at
            // this path
        catch (IOException e) {






My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!