In this section, you will learn how to get the content type of the specified file.
Description of code:
This is essential part of the file. In various applications, there is a use of content type. Here we have used java.net.* package to find out the content type of the file.
URL- This class represents a Uniform Resource Locator. It point to a particular resource, resource can be either a file , directory or an object. Here it refers to a file.
URLConnection-This is the super class of all classes that represent a communication link between an application and a URL.
openConnection()- This is the method of URL class which represents a
connection to the remote object referred to by the
getContentType()- This method of URLConnection class returns the content type of the file.
Here is the code:
In the above code, we have used URL and URLConnection class to find the content type or mime type of the specified file.
|Content type of file "C:/rose.jpg is: image/jpeg|
Posted on: April 3, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles