Created
May 3, 2018 03:58
-
-
Save efossas/d8c12ed3a3ac5c4edbb628f8b010787e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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