The following example shows how to detect the encoding of the document:
// Create an instance of LoadOptions class with the default ANSI encoding.
// This encoding is returned for ANSI text documents.
LoadOptionsloadOptions=newLoadOptions(FileFormat.WordProcessing,null,null,Charset.forName("US-ASCII"));// Create an instance of Parser class
try(Parserparser=newParser(Constants.SampleText,loadOptions)){// Get the document info
IDocumentInfoinfo=parser.getDocumentInfo();// Check if it's the document info of a plain text document
if(infoinstanceofTextDocumentInfo==false){System.out.println("Isn't a plain text document");return;}// Print the encoding
System.out.println("Encoding: "+((TextDocumentInfo)info).getCharset().displayName());}
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples: