如何在java

时间:2018-04-14 10:11:22

标签: java xml encoding

我必须从特定的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));
    }

}

任何帮助将非常感谢。

0 个答案:

没有答案