0
インターネットからファイルをダウンロードしようとしています。それはうまく動作しますが、ファイルが2MBより大きい場合は、このエラーが発生します。あなたの助けをありがとうAndroidダウンロードファイル
09-13 17:49:05.228 17994-18110/? E/dalvikvm-heap: Out of memory on a 286-byte allocation.
09-13 17:49:06.322 17994-18111/? E/dalvikvm-heap: Out of memory on a 16-byte allocation.
09-13 17:49:07.361 17994-17994/? E/dalvikvm-heap: Out of memory on a 72-byte allocation.
09-13 17:49:08.408 17994-18003/? E/dalvikvm-heap: Out of memory on a 24-byte allocation.
09-13 17:49:09.447 17994-18003/? E/dalvikvm-heap: Out of memory on a 28-byte allocation.
09-13 17:49:09.994 17994-18111/? E/dalvikvm-heap: Out of memory on a 28-byte allocation.
09-13 17:49:10.541 17994-17994/? E/dalvikvm-heap: Out of memory on a 28-byte allocation.
public static byte[] is2Bytes(InputStream is) {
byte[] buf = null;
BufferedInputStream bufIS = null;
if (is != null)
try {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
bufIS = new BufferedInputStream(is);
buf = new byte[4096];
int cnt;
while ((cnt = bufIS.read(buf)) >= 0) {
byteBuffer.write(buf, 0, cnt);
}
buf = byteBuffer.size() > 0 ? byteBuffer.toByteArray() : null;
} catch (Exception ignore) {
} finally {
try {
if (bufIS != null) bufIS.close();
} catch (Exception ignore) {
}
}
return buf;
}
例がありますか? – user2847219
@ user2847219:https:/// L73 – CommonsWare