[英]Read xml file properties from URL
I'm trying to read some properties from a file which I have in a URL and when I do it, I have these properties to null and I don't know why. 我正在尝试从URL中包含的文件中读取一些属性,当我这样做时,我会将这些属性设置为null,但我不知道为什么。 This is my code:
这是我的代码:
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");
Why happen this? 为什么会这样? I just have the last line and this is the output of the xml:
我只有最后一行,这是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>
You could use HttpURLConnection
to get your InputStream
. 您可以使用
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.