去除富文本格式
1、写一个公共类
package com.boyutec.oss.sys.util;
import java.io.bytearrayinputstream;
import java.io.ioexception;
import java.io.inputstream;
import java.io.inputstreamreader;
import java.io.reader;
import javax.swing.text.html.htmleditorkit;
import javax.swing.text.html.parser.parserdelegator;
public class html2text extends htmleditorkit.parsercallback {
private static html2text html2text = new html2text();
stringbuffer s;
public html2text() {
}
public void parse(string str) throws ioexception {
inputstream iin = new bytearrayinputstream(str.getbytes());
reader in = new inputstreamreader(iin);
s = new stringbuffer();
parserdelegator delegator = new parserdelegator();
// the third parameter is true to ignore charset directive
delegator.parse(in, this, boolean.true);
iin.close();
in.close();
}
public void handletext(char[] text, int pos) {
s.append(text);
}
public string gettext() {
return s.tostring();
}
public static string getcontent(string str) {
try {
html2text.parse(str);
} catch (ioexception e) {
e.printstacktrace();
}
return html2text.gettext();
}
}
2、可以直接调用:html2text.getcontent("需要处理的字符串);
上一篇: css3实例教程 一款纯css3实现的环形导航菜单
下一篇: 在oracle中,什么是序列?