使用url连接上载文件时的堆大小警告

时间:2011-02-11 18:23:42

标签: android upload httpurlconnection

我正在尝试使用HttpUrlConnection和put方法将文件上传到Amazon S3。

  outputStream = new DataOutputStream( connection.getOutputStream() );
        bytesAvailable = fileInputStream.available();
        int current = 0;
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // Read file
        bytesRead = fileInputStream.read(buffer, 0, bufferSize);

        while (bytesRead > 0)
       {
            outputStream.write(buffer, 0, bufferSize);
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            current+=bytesRead;
        }

这是使用缓冲区输出数据的正确方法吗?这一切都适用于较小的文件,但当我尝试上传更大的东西时,它说

02-11 19:04:38.718: INFO/dalvikvm-heap(15385): Grow heap (frag case) to 9.204MB for 3143696-byte allocation
我在做错了什么? 任何帮助都非常感谢,谢谢。

0 个答案:

没有答案