Java敏感字符处理类

欢迎进入Java社区论坛,与200万技术人员互动交流 >>进入

  * 替换掉字符串中的敏感词

  *

  * @param str 等待替换的字符串

  * @param replaceChar 替换字符

  * @return

  */

  public static String replace(String str,String replaceChar){

  checkReload();

  for(String word : words){

  if(str.indexOf(word)>=0){

  String reChar = “”;

  for(int i=0;i<word.length();i++){

  reChar += replaceChar;

  }

  str = str.replaceAll(word, reChar);

  }

  }

  return str;

  }

  public static List<String> lists() {

  checkReload();

  return words;

  }

  /**

  * 添加敏感词

  *

  * @param word

  * @throws IOException

  */

  public static void add(String word) throws IOException {

  word = word.toLowerCase();

  if(!words.contains(word)){

  words.add(word);

  FileUtils.writeLines(wordfilter, “UTF-8”, words);

  lastModified = wordfilter.lastModified();

  }

  }

  /**

  * 删除敏感词

  *

  * @param word

  * @throws IOException

  */

  public static void delete(String word) throws IOException {

  word = word.toLowerCase();

  words.remove(word);

  FileUtils.writeLines(wordfilter, “UTF-8”, words);

  lastModified = wordfilter.lastModified();

  }

  public static void main(String[] args) throws Exception{

  System.out.println(BadWord.replace(”中国共产党钓鱼岛”,”*”));

  System.out.println(BadWord.isContain(”岛”));

  BadWord.add(”傻逼”);

  }

  }

[1][2]

于是夜莺会在黎明到来之前勇敢的将胸膛顶住蔷薇的刺,

Java敏感字符处理类

相关文章:

你感兴趣的文章:

标签云: