Here you can find the source of htmlEncode(String s)
public static String htmlEncode(String s)
//package com.java2s; //License from project: Open Source License public class Main { public static String htmlEncode(String s) { StringBuffer out = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c > 127 || c == '"' || c == '<' || c == '>') { out.append("&#" + (int) c + ";"); } else { out.append(c);//from ww w . java 2 s. c o m } } return out.toString(); } }