日期:2014-05-20 浏览次数:20994 次
public String FileText(File html) { String htmlPath = html.getAbsolutePath(); String text = ""; Parser parser = null; try { parser = new Parser(htmlPath); } catch (ParserException e) { e.printStackTrace(); } try { parser.setEncoding("UTF-8"); } catch (ParserException e) { e.printStackTrace(); } HtmlPage visitor = new HtmlPage(parser); try { parser.visitAllNodesWith(visitor); } catch (ParserException e) { e.printStackTrace(); } NodeList nodes = visitor.getBody(); int size = nodes.size(); for (int i = 0; i < size; i++) { Node node = nodes.elementAt(i); text += node.toPlainTextString(); } return text; }
------解决方案--------------------