Getting A File's Mime Type In Java

后端 未结 23 2778
南方客
南方客 2020-11-21 06:53

I was just wondering how most people fetch a mime type from a file in Java? So far I\'ve tried two utils: JMimeMagic & Mime-Util.

Th

23条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 07:24

    If you are stuck with java 5-6 then this utility class from servoy open source product.

    You only need this function

    public static String getContentType(byte[] data, String name)
    

    It probes the first bytes of the content and returns the content types based on that content and not by file extension.

提交回复
热议问题