1
我一直在嘗試使用以下代碼片段從URL中檢索XML數據並將其寫入磁盤http://dbpedia.org/data/Berlin.rdf
上的文件。如何從Java中使用鏈接URL檢索XML/RDF數據?
URL urlObj = new URL("http://dbpedia.org/data/Berlin.rdf");
java.net.HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
InputStream reader = new BufferedInputStream(connection.getInputStream());
BufferedReader breader = new BufferedReader(new InputStreamReader(reader));
String line;
BufferedWriter writer = new BufferedWriter(new eWriter("resource.xml"));
while ((line = breader.readLine()) != null) {
// writes the line to the output file
writer.write(line);
System.out.println(line);
}
writer.close();
connection.disconnect();
但我得到這個錯誤:例外在線程「主要」 java.io.IOException異常:服務器返回的HTTP響應代碼:502網址:http://dbpedia.org/data/Berlin.rdf 什麼是錯的?如何解決這個問題?提前致謝。
我能夠沒有錯誤地運行。 – Eranda