[英]Accept xml message in java from server
我是使用Web服務的新手,對不起這個簡單的問題。 我想用Java從服務器接收xml消息或文件,然后解析它並尋求幫助。
讀取內容並另存為文件:
URL url = new URL("https://example.com/abc.xml");
Path xml = Paths.get("/path/to/abc.xml");;
try (InputStream in = url.openStream()) {
Files.copy(in, xml);
}
讀取內容並解析為XML:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
URL url = new URL("https://example.com/abc.xml");
try (InputStream in = url.openStream()) {
Document d = factory.newDocumentBuilder().parse(in);
...
}
這些解決方案使用Java提供的內置類:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.