簡體   English   中英

從URL讀取xml文件屬性

[英]Read xml file properties from URL

我正在嘗試從URL中包含的文件中讀取一些屬性,當我這樣做時,我會將這些屬性設置為null,但我不知道為什么。 這是我的代碼:

Properties propiedades = new Properties(); 

URL url2= new URL("http://localhost:3624/web/applets/paqProperties/configuration.xml");
InputStream in =url2.openStream();
Reader reader = new InputStreamReader(in);
propiedades.load(reader);
//propiedades.loadFromXML(new FileInputStream("paqProperties/configuration.xml"));
//propiedades.load(new FileInputStream("paqProperties/configuracion.properties"));

soapAction=propiedades.getProperty("soapAction");
servidor=propiedades.getProperty("servidor");
url=propiedades.getProperty("urlWS");

為什么會這樣? 我只有最后一行,這是xml的輸出:

   <properties>
    <entry key="soapAction">http://localhost:3624/</entry>
    <entry key="servidor">http://localhost:3624/web/soa/</entry>
    <entry key="urlWS">http://localhost:3624/web/soa/soa.asmx</entry>
    <entry key="servidor2">http://localhost:3624/web/soa/</entry>
    <entry key="soapAction2">http://localhost:3624/web/soa/getURL</entry>
   </properties>

您可以使用HttpURLConnection來獲取InputStream

String uri = YOUR_URL
URL url = new URL(uri);
HttpURLConnection connection =
    (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");

InputStream xml = connection.getInputStream();

...

connection.disconnect();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM