import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
public class TestDownFile {
public static void main(String[] args){
String sURL ="http://localhost:8080/hrproject/book.rar";
int nStartPos=0;
int nRead=0;
String sName="book.rar";
String sPath="e:\\temp";
try {
URL url = new URL(sURL);
//打开连接
HttpURLConnection httpConnection = (HttpURLConnection) url
.openConnection();
//获得文件长度
long nEndPos =getFileSize(sURL);
RandomAccessFile oSavedFile= new RandomAccessFile(sPath+"\\"+sName, "rw");
httpConnection.setRequestProperty("User-Agent", "Internet Explorer");