OutputStream OutOfMemoryError when sending HTTP

前端 未结 6 1745
深忆病人
深忆病人 2020-12-01 16:53

I am trying to publish a large video/image file from the local file system to an http path, but I run into an out of memory error after some time...

here is the code

6条回答
  •  -上瘾入骨i
    2020-12-01 17:26

    For anything other than basic GET operations, the built-in java.net HTTP stuff isn't very good. Using Apache Commons HttpClient is recommended for this. It lets you do much more intuitive stuff like this:

    PutMethod put = new PutMethod(url);
    put.setRequestEntity(new FileRequestEntity(localFile, contentType));
    int responseCode = put.executeMethod();
    

    which replaces a lot of your boiler-plate code.

提交回复
热议问题