请问一下,怎样将修改过得html保存到文件中
code如下
parser = new Parser(getContentByLocalFile(file));
NodeFilter nt = new NodeClassFilter(ImageTag.class) ;
NodeList tmpImageList = (NodeList) parser.parse(nt);
/*linkTmpHash = new Hashtable();
for (int i = 0; i < length; i++) {
Element tmpElement = (Element) tmpNodeList.item(i);
String href = tmpElement.getAttribute("href");
if (href != null && !href.equals("")) {
linkTmpHash.put(href, "");
}
}
data.setHrefs((String[]) linkTmpHash.keySet().toArray(new String[linkTmpHash.size()]));*/
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter (new FileOutputStream (file)));
linkTmpHash = new Hashtable();
for (int i = 0; i < tmpImageList.size(); i++) {
imgnode = (ImageTag)tmpImageList.elementAt(i);
String src = imgnode.getImageURL();
if (URLPathNameUtil.isAbsolutePath(src)) {
if (testAbsolutePath) {
testImagetag(file,src);
}
} else {
if (testRelativePath) {
testImagetag(file, src);
}
}
if(getRealPath()!=null){
imgnode.setImageURL(getRealPath());
writer.write(tmpImageList.toHtml());
}
/*if (src != null && !src.equals("")) {
linkTmpHash.put(src, "");
}*/
}
writer.flush();
writer.close ();
谢谢了
回复 更多评论