Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a java library equivalent to file command in unix

Tags:

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)

I know I can run the command file, but I am looking for a java library, not running the actual unix command.

like image 331
Shervin Asgari Avatar asked Apr 28 '10 11:04

Shervin Asgari


1 Answers

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
like image 75
Hasturkun Avatar answered Nov 13 '22 01:11

Hasturkun