Reputation: 1291
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
Reputation: 10927
Use mime-util's MagicMimeMimeDetector:
detector.getMimeTypes(file)
Upvotes: 0
Reputation: 2174
File f = new File(filepath);
System.out.println("Mime Type of " + f.getName() + " is " +
new MimetypesFileTypeMap().getContentType(f));
Upvotes: 4