繁体   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