import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
public class text {
public static void main(String[] args){
String sURL ="http://192.168.0.253/text.rar";
int nStartPos=0;
int nRead=0;
String sName="text.rar";
String sPath="d:\\temp";
try {
URL url = new URL(sURL);
//打开连接
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
//获得文件长度
long nEndPos =getFileSize(sURL);
//保存数据记录的文件(读写方式)
RandomAccessFile oSavedFile= new RandomAccessFile(sPath+"\\"+sName, "rw");
//设置User-Agent
httpConnection.setRequestProperty("User-Agent", "Internet Explorer");
String sProperty = "bytes=" + nStartPos + '-' ;
//告诉服务器所要的文件从nStartPos字节开始传
//设置断点续传的开始位置
httpConnection.setRequestProperty("RANGE", sProperty);
System.out.println(sProperty);
//获得输入流。从输入流中取出的字节流就是文件从0开始的字节流。
InputStream input = httpConnection.getInputStream();