OutOfMemoryError
在 Android 中发布大文件时,我有时会遇到问题。这是我正在使用的代码。难道我做错了什么?
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
ostream = new DataOutputStream(con.getOutputStream());
byte[] buffer = new byte[1536];
int count;
while ((count = fileInput.read(buffer)) != -1) {
ostream.write(buffer, 0, count); // This sometimes causes OutOfMemoryError
}
ostream.flush();
ostream.flush()
在循环内调用while
会有用吗?