How Java obtains the Content-type file type MIME type

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.