1
실제로 RSS 리더 인 Android 앱을 만들고 싶습니다. 그러면 http://kalaerkantho.com/rss.xml과 같은 특정 링크의 XML 파일이로드됩니다. 다운로드 후 나는 그것을 파싱하는 방법을 안다. 하지만 내 질문은 다운로드 한 파일을 처리 할 수 있도록 먼저 다운로드하는 것입니다.XML 파일을 온라인으로로드하고 처리하는 방법은 무엇입니까?
실제로 RSS 리더 인 Android 앱을 만들고 싶습니다. 그러면 http://kalaerkantho.com/rss.xml과 같은 특정 링크의 XML 파일이로드됩니다. 다운로드 후 나는 그것을 파싱하는 방법을 안다. 하지만 내 질문은 다운로드 한 파일을 처리 할 수 있도록 먼저 다운로드하는 것입니다.XML 파일을 온라인으로로드하고 처리하는 방법은 무엇입니까?
이 시도 :
private static void downloadFile(String url, String filePath) {
try {
File outputFile = new File(filePath);
URL u = new URL(url);
URLConnection conn = u.openConnection();
int contentLength = conn.getContentLength();
DataInputStream stream = new DataInputStream(u.openStream());
byte[] buffer = new byte[contentLength];
stream.readFully(buffer);
stream.close();
DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile));
fos.write(buffer);
fos.flush();
fos.close();
} catch(FileNotFoundException e) {
return; // swallow a 404
} catch (IOException e) {
return; // swallow a 404
}
}
는
this answer에서 적응.