我正在使用JTidy,我想给它一个字符串作为输入,而不是一个文件。这有可能吗?我怎么能做到这一点?
这是我的代码:
FileInputStream fis =null;
String htmlFileName = "report.html";
//from html to xhtml
try
{
fis = new FileInputStream(htmlFileName);
}
catch (java.io.FileNotFoundException e)
{
System.out.println("File not found: " + htmlFileName);
}
Tidy tidy = new Tidy();
tidy.setShowWarnings(false);
tidy.setXmlTags(false);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);//
tidy.setMakeClean(true);
Document xmlDoc = tidy.parseDOM(fis, null);
try
{
tidy.pprint(xmlDoc,new FileOutputStream("report.xhtml"));
} 发布于 2013-03-11 19:27:22
将FileInputStream替换为从String读取的流,例如
try
{
fis = new ByteArrayInputStream(string.getBytes());
} catch (java.io.IOException e) {
System.out.println("Error reading string");
return;
} https://stackoverflow.com/questions/15337357
复制相似问题