在unix中是否有一个等同于file命令的java库 [英] Is there a java library equivalent to file command in unix
问题描述
有没有类似于unix的命令文件
的java库?
Is there any java library that is similar to unix's command file
?
ie:
$ file somepicture.png
somepicture.png PNG image, 805 x 292, 8-bit/color RGB, non-interlaced
文件命令是一个很好的工具。我需要的东西可以告诉我文件是否真的是我想要的。 (即图片,文档等)
The file command is such a nice tool. I need something that can tell me if the file is really what I want it to be. (ie a picture, document etc)
我知道我可以运行命令 file
,但我正在寻找一个java库,没有运行实际的unix命令。
I know I can run the command file
, but I am looking for a java library, not running the actual unix command.
推荐答案
一个快速的谷歌搜索(对于公认的非显而易见的)java magic file detection带来了一篇相当不错的文章,从文件中获取Mime类型,建议您使用以下某项:
A quick google search (for the admittedly non-obvious) "java magic file detection" brings up a fairly nice looking article, "Get the Mime Type from a File" which suggests you use one of the following:
- Apache Tika
- JMimeMagic
这篇关于在unix中是否有一个等同于file命令的java库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!