jmimemagic: 找出文件的MIMIE类型

jmimemagic这个开源软件可以让你用java语言找出某个文件的MIME类型

比如,判断文件是不是文本文件。

    
        private boolean isTextFile(File file) {           
                MagicMatch magic = Magic.getMagicMatch(file, false, true);
                String mimeType = magic.getMimeType().toLowerCase();
                return mimeType.startsWith("text/");

        }

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.