Interface/enum listing standard mime-type constants

前端 未结 11 1993
-上瘾入骨i
-上瘾入骨i 2020-12-13 11:35

I am looking among the standard libraries (like apache commons, jax, jboss, javax) for an interface or enum that lists the values of all the standard mime-type (aka content-

11条回答
  •  旧巷少年郎
    2020-12-13 12:21

    Java 7 to the rescue!

    You can either pass the file or the file name and it will return the MIME type.

    String mimeType = MimetypesFileTypeMap
        .getDefaultFileTypeMap()
        .getContentType(attachment.getFileName());
    

    http://docs.oracle.com/javase/7/docs/api/javax/activation/MimetypesFileTypeMap.html

提交回复
热议问题