package com.download;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
public class Downloader {
      
    public void download() throws IOException
    {
        String fileName = "YNote.exe";
        String path = "http://download.ydstatic.com/notewebsite/downloads/YNote.exe";
        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestMethod("GET");
        int fileLength = conn.getContentLength();
          
        RandomAccessFile file = new RandomAccessFile(fileName,"rw");
        file.setLength(fileLength);
        file.close();
        conn.disconnect();
          
        int threadNum = 10;  //线程数
        //每条线程下载的长度
        int threadLength = fileLength % threadNum == 0 ?
                fileLength/threadNum : fileLength/threadNum + 1;
          
        for(int i=0;i