Я хочу загрузить файл на сетевой сервер, используя коды.но когда размер> 6M , бросить ФАТАЛЬНОЕ ИСКЛЮЧЕНИЕ java.lang.OutOfMemoryError
HttpURLConnection conn;
URL url = new URL(mServerUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", file.getContentType());
conn.setRequestProperty("Connection", "close");
conn.setRequestProperty("Charset", "UTF-8");
conn.connect();
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
int totalSize = 0;
byte[] buffer = new byte[1024];
int len = 0;
while ((len = file.getInStream().read(buffer, 0, 1024)) != -1) {
totalSize += len;
WDLog.i("totalSize = " + totalSize);
os.write(buffer, 0, len);
}
file.getInStream().close();
os.flush();
os.close();
что я могу сделать, чтобы решить вопрос ??спасибо
есть информация logcat:
12-26 19:35:06.976: D/dalvikvm(8952): GC_FOR_MALLOC freed 36718 objects / 1675552 bytes in 53ms
12-26 19:35:06.976: I/dalvikvm-heap(8952): Forcing collection of SoftReferences for 12580880-byte allocation
12-26 19:35:07.006: D/dalvikvm(8952): GC_FOR_MALLOC freed 646 objects / 47808 bytes in 34ms
12-26 19:35:07.006: E/dalvikvm-heap(8952): Out of memory on a 12580880-byte allocation.
12-26 19:35:07.006: I/dalvikvm(8952): "Thread-29" prio=5 tid=8 RUNNABLE
12-26 19:35:07.006: I/dalvikvm(8952): | group="main" sCount=0 dsCount=0 s=N obj=0x46230978 self=0x30eb98
12-26 19:35:07.006: I/dalvikvm(8952): | sysTid=8980 nice=0 sched=0/0 cgrp=default handle=3159096
12-26 19:35:07.016: I/dalvikvm(8952): | schedstat=( 5075164776 7730011023 9520 )
12-26 19:35:07.016: I/dalvikvm(8952): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:~93)
12-26 19:35:07.016: I/dalvikvm(8952): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
12-26 19:35:07.016: I/dalvikvm(8952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$DefaultHttpOutputStream.write(HttpURLConnectionImpl.java:750)
12-26 19:35:07.016: I/dalvikvm(8952): at java.io.DataOutputStream.write(DataOutputStream.java:101)
12-26 19:35:07.016: I/dalvikvm(8952): at com.amtcmv.upload.UploadImgVidFile.postVid(UploadImgVidFile.java:218)
12-26 19:35:07.016: I/dalvikvm(8952): at com.amtcmv.upload.UploadImgVidFile.run(UploadImgVidFile.java:95)
12-26 19:35:07.016: I/dalvikvm(8952): at java.lang.Thread.run(Thread.java:1102)
12-26 19:35:07.016: E/dalvikvm(8952): Out of memory: Heap Size=19783KB, Allocated=9352KB, Bitmap Size=162KB
12-26 19:35:07.016: W/dalvikvm(8952): threadid=8: thread exiting with uncaught exception (group=0x400259f8)
12-26 19:35:07.026: E/AndroidRuntime(8952): FATAL EXCEPTION: Thread-29
12-26 19:35:07.026: E/AndroidRuntime(8952): java.lang.OutOfMemoryError
12-26 19:35:07.026: E/AndroidRuntime(8952): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:93)
12-26 19:35:07.026: E/AndroidRuntime(8952): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:218)
12-26 19:35:07.026: E/AndroidRuntime(8952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$DefaultHttpOutputStream.write(HttpURLConnectionImpl.java:750)
12-26 19:35:07.026: E/AndroidRuntime(8952): at java.io.DataOutputStream.write(DataOutputStream.java:101)
12-26 19:35:07.026: E/AndroidRuntime(8952): at com.amtcmv.upload.UploadImgVidFile.postVid(UploadImgVidFile.java:218)
12-26 19:35:07.026: E/AndroidRuntime(8952): at com.amtcmv.upload.UploadImgVidFile.run(UploadImgVidFile.java:95)
12-26 19:35:07.026: E/AndroidRuntime(8952): at java.lang.Thread.run(Thread.java:1102)
и
os.write (буфер, 0, len);
эта строка выдает ошибку.