Here you can find the source of javaEncode(String txt)
public static String javaEncode(String txt)
//package com.java2s; //License from project: Apache License public class Main { public static String javaEncode(String txt) { if ((txt == null) || (txt.length() == 0)) { return txt; }//www . j a v a 2 s . c om txt = replace(txt, "\\", "\\\\"); txt = replace(txt, "\r\n", "\n"); txt = replace(txt, "\r", "\\r"); txt = replace(txt, "\t", "\\t"); txt = replace(txt, "\n", "\\n"); txt = replace(txt, "\"", "\\\""); txt = replace(txt, "'", "\\'"); return txt; } public static String replace(String str, String subStr, String reStr) { if (str == null) { return null; } if ((subStr == null) || (subStr.equals("")) || (reStr == null)) { return str; } return str.replace(subStr, reStr); } }