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. 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:
<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
.
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.