JSP Mime Type for Multipurpose Internet Mail Extension. MIME is a describe technique for attaching files to Internet mail by changing the raw binary files to printable ASCII. It is expanded being used in HTTP describe the content of messages and downloads from to and from servers.
Understand with Example
In this section, you will learn how to get the mime type of the specified file. The mimeType.jsp contain a page import directive that show you the package java.io is imported. You can see in the given example that we have used the class MimetypesFileTypeMap that will map the specified file to a Mime Type. The MimetypesFilesTypeMap extends FileTypeMap provides datatying of files via their file extension. This uses the .mime type format. The method getContentType(file) of this class return the MIME type based on the specified file name. In the given below example the mime type of file is rose.gif is image/gif.
List of Method used :
MimetypesFileTypeMap().getContentType(file)): This is used to return the MIME type based on the specified file name.
Here is the code of mimeType.jsp:
|<%@ page import="java.io.*"%>
<%@ page import="javax.activation.MimetypesFileTypeMap"%>
<title>Get Mime Type</title>
File file = new File("rose.gif");
out.println("Mime Type of " + file.getName() + " is " +
Output will be displayed as:
Posted on: February 3, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles