am loading xml file from Assets folder. am getting OutOfMemoryError. The code which i have used is
private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + NEW_LINE);
}
reader.close();
} catch (IOException e) {
//do nothing.
} finally {
try {
reader.close();
} catch (IOException e) {
//do nothing.
}
}
reader=null;
return sb.toString();
}
Is there an alternate way to get rid of this Exception. It will be more helpful if you post any code. Thanks in advance.
It's not a good idea to parse a big Xml using a String. You should turn to a streaming version of the parser. Google Http Java Client proposes such a library : http://code.google.com/p/google-http-java-client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With