Eric
Eric

Reputation: 1291

Read file headers using java

I am trying to read file headers using java, I want to get file type(image, audio whatever). I have tried many examples but nothing seems to work. I tried preon and no luck, can some one tell me how to read file headers using preon or some other Java apis thanks...

Upvotes: 2

Views: 4179

Answers (2)

Wilfred Springer
Wilfred Springer

Reputation: 10927

Use mime-util's MagicMimeMimeDetector:

detector.getMimeTypes(file)

Upvotes: 0

Dilip Godhani
Dilip Godhani

Reputation: 2174

 File f = new File(filepath);
 System.out.println("Mime Type of " + f.getName() + " is " +  
 new MimetypesFileTypeMap().getContentType(f));

Upvotes: 4

Related Questions