0

I want to get mimetype of a file can anyone please help me I want MIME Type like this...

File file=new File("example.jpeg");
String MimeTypeOfFile=/*files mimetype*/;

Thank You in Advance

DiLDoST
  • 335
  • 3
  • 12
  • 2
    https://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java – Zun Jun 21 '18 at 15:26
  • 2
    Possible duplicate of [How to determine MIME type of file in android?](https://stackoverflow.com/questions/8589645/how-to-determine-mime-type-of-file-in-android) – Jake Lee Jun 21 '18 at 15:29
  • Possible duplicate of [Getting A File's Mime Type In Java](https://stackoverflow.com/questions/51438/getting-a-files-mime-type-in-java) – Marc Estrada Jun 21 '18 at 15:36
  • Kinda like that but a bit different. Java version varries on different Android APIs. And on most of the phones it's less than Java 7 so that way is not fair enough. And if we talk about the MimeMap? It's so very limited. However i made my own class to do it as it has nearly more than thousands of extensions and their mime types as i feeded to use ;-) – DiLDoST Jun 07 '21 at 20:00

1 Answers1

3

You can use the Apache Tika Library: It detects and extracts metadata and text from over a thousand different file types

http://tika.apache.org/0.7/detection.html

It has various methods like extension checking or reading file data to detect mime-type. It would be easy and efficient rather than writing yourself.

Example :

System.out.println(new Tika().detect(new File(PATH_TO_FILE)));
exploitr
  • 843
  • 1
  • 14
  • 27
  • ! Sorry but this is not what i needed, however thanks for it. I have found my way on how to do it. Tho' the path you shown is so damn opposite of what i want in need. The lib is more than 70mb, while i don't want to use any other libs as because i don't want my app to grow so up like that. Thanks for the ans but wasn't useful – DiLDoST Jun 07 '21 at 19:57
  • "While I don't want to use any other libs because I don't want my app to grow so up like that" - *you didn't mention that in your question*. Basically, you mentioned no extra info than the main problem itself. – exploitr Jul 21 '21 at 18:56
  • Yeah you are right, but however my big bro i got it na by self codding HAHAHA found a way and made my own util – DiLDoST Jul 27 '21 at 19:57