Skip to content

Instantly share code, notes, and snippets.

@efossas
Created May 3, 2018 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efossas/d8c12ed3a3ac5c4edbb628f8b010787e to your computer and use it in GitHub Desktop.
Save efossas/d8c12ed3a3ac5c4edbb628f8b010787e to your computer and use it in GitHub Desktop.
/* import Tika into a file with this */
import org.apache.tika.Tika;
/*
assume the file's content is in a string called 'file'
you can detect a file's mime type with the following
https://tika.apache.org/1.8/api/org/apache/tika/Tika.html#detect(byte[])
*/
String detectedFileType = (new Tika()).detect(file.getBytes())
if ("text/plain".equals(detectedFileType)) {
// a match! the file is plain text
} else {
// no match!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment