How to accurately determine mime data from a file?

后端 未结 3 541
谎友^
谎友^ 2020-12-05 05:38

I\'m adding some functionality to a program so that I can accurately determine the files type by reading the MIME data. I\'ve already tried a few methods:

Method 1:

3条回答
  •  温柔的废话
    2020-12-05 06:12

    I'm not entirely sure how accurate it is, but this worked for me in simple cases.

        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String type = fileNameMap.getContentTypeFor(filePath);
    

提交回复
热议问题