2014-12-19 3 views
1

URL에있는 파일에서 일부 속성을 읽으려고합니다.이 작업을 수행 할 때 이러한 속성이 null이고 그 이유를 모르겠습니다. 내 코드는 다음과 같습니다.URL에서 xml 파일 속성을 읽으십시오.

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> 
+1

'propiedades' 란 무엇입니까? –

+0

'curl'또는 웹 브라우저를 통해 URL에 액세스하면 어떻게됩니까? xml 파일을 가져 왔습니까? – Simon

+0

예 알아보기. 잘 모르겠다. – zoit

답변

0

당신은 당신의 InputStream를 얻을 수 HttpURLConnection를 사용할 수 있습니다.

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(); 
관련 문제