In the HTTP request. Sometimes you need to know the type of content-type, especially when uploading files. More important. Although some methods can be solved, but are not too accurate or cumbersome, simply I found an open source class library can solve the relatively perfect problem, it is jmimemagic.
Jmimemagic is a Java class library that is used to detect the MIME type of a file or data stream.
The latest version number is v 0.1.2.
Jar Kit Required: Commons-logging-1.0.x.jar,log4j-1.2.x.jar
: Click to open link
It is very easy to use, such as the following:
File File = new file ("E:\\test\\123.gif") MagicMatch match = Magic.getmagicmatch (file, False, True); String ContentType = Match.getmimetype (); System.out.println (ContentType);
It's just that the method is less efficient. It's a disadvantage.
How Java obtains the Content-type file type MIME type