how to resume an interrupted download

后端 未结 2 1079
日久生厌
日久生厌 2020-12-02 06:49

I\'m trying to download a large file from my Yahoo! web site server which apparently is setup (not by me) to disconnect downloads if they are not completed within 100 second

2条回答
  •  一生所求
    2020-12-02 07:41

    Try using a "Range" request header:

    // Open connection to URL.
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    
    // Specify what portion of file to download.
    connection.setRequestProperty("Range", "bytes=" + downloaded + "-");
    // here "downloaded" is the data length already previously downloaded.
    
    // Connect to server.
    connection.connect();
    

    Having done that, you can seek at a given point (just before the length of your download data, say X) and start writing the newly downloaded data there. Be sure to use the same value X for the range header.

    Details about 14.35.2 Range Retrieval Requests

    More details and source code can be found here

提交回复
热议问题