How to get file extension from content type?

后端 未结 4 907
星月不相逢
星月不相逢 2021-01-11 09:48

I\'m using Apache Tika, and I have files (without extension) of particular content type that need to be renamed to have extension that reflect the content type.

Any

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 10:21

    You want to look at file tika-mimetypes.xml -> check out tika's source code and :

    org.apache.tika.mime.MimeTypesReader
    
         } else if (nodeElement.getTagName().equals(GLOB_TAG)) {
             boolean useRegex = Boolean.valueOf(nodeElement.getAttribute(ISREGEX_ATTR));
             types.addPattern(type, nodeElement.getAttribute(PATTERN_ATTR), useRegex);
    

    You can then work wit

    org.apache.tika.mime.MimeTypes
    
          private Patterns patterns = new Patterns(registry);
    

提交回复
热议问题