This method should be check if a file is MIME type. To achieve this goal I am using method probeContentType().
However maybe is another way to decide same question. Whic
You can use String mimeType = new MimetypesFileTypeMap().getContentType(theFile);
.
Note that if no MIME type is found, application/octet-stream
is returned instead of null
.
There are 2 approaches for getting a file mime type:
The following solution use the 1st approach:
The following solution use the 2nd approach:
For some more information see this post
Another alternative is to Use URLConnection.guessContentTypeFromName(String fileName)
if you cannot use Java 7.
Note that if the content type cannot be guessed, the method will return null
.