Sample code for 30+ languages & platforms
Java

Convert HTML to Plain Text

Demonstrates how to convert HTML to plain text.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  This example requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    CkHtmlToText h2t = new CkHtmlToText();

    String html = h2t.readFileToString("c:/temp/test.html","utf-8");
    if (h2t.get_LastMethodSuccess() == false) {
        System.out.println(h2t.lastErrorText());
        return;
        }

    String plainText = h2t.toText(html);
    if (h2t.get_LastMethodSuccess() == false) {
        System.out.println(h2t.lastErrorText());
        return;
        }

    System.out.println(plainText);
  }
}