Search code examples
javaandroidfilefile-type

How to know the filetype?


I want to know whether the file is Audio(mp3,aac, etc), Video(mp4,wmv,3gp,etc), Document(txt,rtf,doc,docx,xls,xlsx,ppt,html etc) or Unknown (with no extension and other custom extension specific for one single application in the near future)

I need to implement it in Android. I think I could find the extension of file and identifying its type? Or do I not need to know the extension?

I just want to know the file-type.


Solution

  • You can either try to guess the file type from the filename extension using guessContentTypeFromName(), or you can try to guess the file type from the content using guessContentTypeFromStream().