The escapeHtml() method of the StringEscapeUtils class in the Commons LangS library can be used to convert a String to its HTMLW entity representation. As an example, this would convert an ampersand (&) in a String to its HTML entity equivalent (&amp;).

The HtmlEscapeTest class demonstrates this. It reads a String of text from the input.txt file (using FileUtils from Commons IOS) and substitutes HTML entities using the StringEscapeUtils.escapeHtml() method. It outputs the resulting String to the console.