Abstract Interface FileNameMap in Java

Abstract Interface FileNameMap in Java

FileNameMap interface defines a single method that is called to obtain the MIME type of a file based on the name of a file. The fileNameMap field of the URLConnection class refers to an object that implements this interface.

The mapping is typically done by examining the file extension of the filename, or in other words, the part of the filename that follows the final period.

The filename-to-file-type map it implements is used by the static URLConnection.guessContentTypeFromName() method.

The structure of the Abstract Interface FileNameMap in Java is given by

public abstract interface java.net.FileNameMap{
// Public Instance Methods
public abstract String getContentTypeFor(String fileName);
}

The details of the class structure are given as follows:

public abstract String getContentTypeFor(String fileName);

public abstract String getContentTypeFor(String fileName) method attempts to determine the MIME type of a file by examining its filename.

This method returns the String that contains the MIME type that corresponds to the filename.

Parameter
fileName – A String that contains a filename.

Share and Enjoy !

See also  Class FileDescriptor in Java

Leave a Reply

Your email address will not be published. Required fields are marked *