http 요청을하고 있습니다. 거대한 데이터를 받아야하지만 데이터를 읽는 동안 OutOfMemory 예외가 발생합니다.OutOfMemory http에서 데이터를 읽는 중 오류가 발생했습니다. android
내 코드 :
public static String getData(String url) throws CustomException {
// http post
InputStream is = null;
StringBuilder sb = null;
String result = null;
HttpGet httppost;
HttpEntity entity;
try {
HttpClient httpclient = new DefaultHttpClient();
httppost = new HttpGet(url);
HttpResponse response = httpclient.execute(httppost);
entity = response.getEntity();
is = entity.getContent();
Log.e("log_tag", "connection success ");
} catch (Exception e) {
Log.e("log_tag", "Error in http connection" + e.toString());
throw new CustomException("Could not establish network connection");
}
// convert response to string
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c;
byte buffer[] = new byte[1024];
while ((c = is.read(buffer)) > -1)
baos.write(buffer, 0, c); //**OutOfMemory Exception.**
byte[] data = baos.toByteArray();
is.close();
result = new String(data, 0, data.length, "utf-8");
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
throw new CustomException("Error parsing the response");
}
return result;
}
URL 내가 GetData의에 전달할 수 있습니다 : http://ec2-50-19-105-251.compute-1.amazonaws.com/ad/Upload/getitemlist09122013014749.txt
방법이 문제를 해결하는 날을 제안하십시오.
거기에 왜 그렇게 많은 레코드가 있습니다. 나는 당신이 sdcard 또는 휴대 전화 스토리지에 응용 프로그램을 설치해야한다고 생각합니다. – Riser
친구, URL이 많은 데이터를 반환합니다. 그것을 메모리에 추가하지 마십시오. 파일 시스템을 사용하십시오. –