[英]How to retrieve XML/RDF data from a link URL using in Java?
我一直在嘗試使用以下代碼段從URL檢索XML數據並寫入磁盤http://dbpedia.org/data/Berlin.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();
但是我收到此錯誤:線程“ main”中的異常java.io.IOException:服務器返回的HTTP響應代碼:502 for URL: http : //dbpedia.org/data/Berlin.rdf這是什么問題? 如何解決呢? 提前致謝。
502 HTTP錯誤是服務器錯誤。
如果您訪問該站點( http://dbpedia.org/data/Berlin.rdf ),則會看到dbpedia當前正在維護中。 請過幾個小時再返回,然后重試,您的代碼應該可以正常工作。
更新:現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.