我需要将至少 16 Mb 的文件从 Android 上传到我的服务器,但是当文件超过 9 Mb 时会出现下一个错误->
10-17 05:21:57.600: E/AndroidRuntime(2185): java.lang.OutOfMemoryError
10-17 05:21:57.600: E/AndroidRuntime(2185): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
10-17 05:21:57.600: E/AndroidRuntime(2185): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
10-17 05:21:57.600: E/AndroidRuntime(2185): at libcore.net.http.RetryableOutputStream.write(RetryableOutputStream.java:61)
10-17 05:21:57.600: E/AndroidRuntime(2185): at java.io.DataOutputStream.write(DataOutputStream.java:98)
这是代码的一部分,如果需要,我可以发布整个代码
String fileName = sourceFileUri;
HttpURLConnection conn = null;
DataOutputStream dos = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1 * 1024 * 1024;
File sourceFile = new File(sourceFileUri);
谢谢
大卫