URL url = new URL (http://www.oschina.net/no-exist.zip );
Httpurlconnection httpconnection = (httpurlconnection) URL. openconnection ();
// Set the User-AgenthttpConnection.setRequestProperty ("User-Agent", "netfox"); // set the start position of the resumable upload httpconnection. setrequestproperty ("range", "bytes = 2000070"); // obtain the input stream inputstream input = httpconnection. getinputstream ();/** the byte stream from which the node no-exist.zip file is obtained from the input stream starting from 2000070. As you can see, it is quite easy to implement resumable upload in Java. The next thing to do is how to save the obtained stream to the file. (2) the method used to save the file I used is the randaccessfile class in the IO package. The operation is quite simple. Assume that the file is saved from 2000070. The Code is as follows: */randomaccessfile osavedfile = new randomaccessfile ("down.zip", "RW"); long NPOs = 2000070; // locate the file pointer to the NPOs position osavedfile. seek (NPOs); byte [] B = new byte [1024]; int nread; // read the byte stream from the input stream and write it to the file while (nread = input. read (B, 0,1024 ))
& Gt; 0) {osavedfile. Write (B, 0, nread );}
From: http://www.oschina.net/code/snippet_54100_623