我正在尝试使用JTidy解析HTML文件,但它似乎忽略了输出中文件的内容,尽管输出日志显示了JTidy通过文件的内容。
public static void Main(String args[]) throws FileNotFoundException, UnsupportedEncodingException {
File file = new File("C:\folder\file.html");
InputStream in = inputStream(file);
OutputStream out = null;
Document doc = cleanData(in, out);
}
public static Document cleanData(InputStream in, OutputStream out) throws UnsupportedEncodingException {
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setForceOutput(true);
tidy.parseDOM(in, out);
Document dom = tidy.parseDOM(in, out);
return dom;
}
public static InputStream inputStream(File file) throws FileNotFoundException {
FileInputStream fis = new FileInputStream(file);
return fis;
}
但它只输出
<?xml version="1.0" encoding="UTF-8" standalone="no"?><html xmlns=""><head><meta content="HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net" name="generator"/><title/></head><body/></html>
有人知道我做错了吗?