MyHtml2Text parser = new MyHtml2Text();try { parser.parse(new StringReader(myTextPane.getText()));} catch (IOException ee) { //handle exception}System.out.println(parser.getText());
Html2Text我链接到的答案上找到的课程的稍作修改的版本
import java.io.IOException;import javax.swing.text.html.*;import javax.swing.text.html.parser.*;public class MyHtml2Text extends HTMLEditorKit.ParserCallback { StringBuffer s; public MyHtml2Text() {} public void parse(Reader in) throws IOException { s = new StringBuffer(); ParserDelegator delegator = new ParserDelegator(); delegator.parse(in, this, Boolean.TRUE); } public void handleText(char[] text, int pos) { s.append(text); s.append("n"); } public String getText() { return s.toString(); }}
如果您需要更细粒度的处理,请考虑实施更多由定义的接口
HTMLEditorKit.ParserCallback
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)