크기가 매우 큰 온라인 XML 파일 (약 33MB)을 저장하고 싶습니다. StringBuilder에서 xml 파일을 가져 와서 문자열로 변환 한 다음 FileOutputStream에 의해 내부 저장소/Sdcard에 파일을 저장하려고합니다.Android - 큰 XML 파일 저장 (내부/sdcard)
하지만 메모리가 부족해 앱이 다운됩니다. 충돌은 StringBuilder에서 문자열의 값을 가져 오려고 할 때 발생합니다.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("sorry cant paste the actual link due copyrights.xml");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
String result = sb.toString();
System.out.println(result);
FileOutputStream fos = openFileOutput("test.xml", Context.MODE_PRIVATE);
fos.write(sb.toString().getBytes());
fos.close();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
이것을 시도해도 결과를 알려줍니다. – ZealDeveloper
완벽하게 작동합니다. 고맙습니다. – ZealDeveloper