我必须从特定的URL读取生成的xml。但是这个xml文件丢失了encoding "UTF-8"
。如何将其添加到我的代码中:
public class crawleycraw {
public static void main(String[] args) throws IOException, TransformerException, SAXException, ParserConfigurationException {
// TODO Auto-generated method stub
String urlString = "http://www.bnb.bg/";
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(conn.getInputStream());
TransformerFactory factoryl = TransformerFactory.newInstance();
Transformer xform = factoryl.newTransformer();
xform.transform(new DOMSource(doc), new StreamResult(System.out));
}
}
任何帮助将非常感谢。