我发送的视频和音频文件从我的Android应用程序,以 Wampserver
,其中的一些可以得到相当大,我往往会得到出现OutofMemory
当文件大约超过 1MB
的大小问题。
I'm sending video and audio files from my Android application to Wampserver
, some of these can get quite large and I tend to get OutofMemory
issues when the file is approximately over 1MB
in size.
我转换中的每个文件到一个字节流。我认为,字节流太大,因此出现OutofMemory
。
I convert each file individually into a byte stream. I think the byte stream is too large hence the OutofMemory
.
我怎样才能防止出现这个错误?
How can I stop this error from occurring?
使用链接最大信号这里建议:
Using the link Maxium suggested here:
上传文件使用POST Android上的HTTP服务器。
然后我发现这个内存错误的机器人修复错误。
I then found this Out of Memory error in android to fix the error.
替换:
while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
与
while (bytesRead > 0){
bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte byt[]=new byte[bufferSize];
fileInputStream.read(byt);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
outputStream.write(buffer, 0, bufferSize);
}