zgh26782000 zgh26782000
关注数: 45 粉丝数: 108 发帖数: 8,155 关注贴吧数: 18
java断点续传 import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class DownLoad {      int readsize = 30000;//每次读取字节数      public static void main(String[] args) {          DownLoad d = new DownLoad();          String url = "http://tieba.baidu.com/mo/q/checkurl?url=http%3A%2F%2Fdl.sj.91.com%2Fpcsuite%2F91assistant_for_android.exe&urlrefer=322c123bda8777e22489291119f7d427";//下载连接          try {              d.dLoad(url);          } catch (Exception e) {              e.printStackTrace();          }      }           private void dLoad(String url)throws Exception      {          String newpath[] = url.split("/");          String np = newpath[newpath.length-1];//截取出的文件名          File f = new File(np);                   long alllen = 0;//剩余下载大小          long nowlen = f.length();//已下载部分大小                   URL ul = new URL(url);          //HttpURLConnection uc = (HttpURLConnection)ul.openConnection();          URLConnection uc = ul.openConnection();          uc.setRequestProperty("User-Agent","NetFox");          uc.setRequestProperty("RANGE","bytes="+(nowlen)+"-");//设置从web开始读取位置                   String ContentLength = uc.getHeaderField("Content-Length");          if(ContentLength != null && ContentLength.trim().matches("[0-9]{1,}"))          {              alllen = Integer.parseInt(ContentLength.trim());//剩余下载大小          }                            System.out.println(nowlen+"/"+alllen);                            InputStream is = uc.getInputStream();          FileOutputStream fo = new FileOutputStream(np,true);                   byte b[] = new byte[readsize];                   int a = is.read(b);//读取          while(a>0)          {              fo.write(b,0,a);//写入              a = is.read(b);//读取          }                   fo.close();          is.close();      } }
div拖动层 var dragdiv = {           //拖动层           //例:dragdiv.registerDragdropHandler("movespan","movediv");           registerDragdropHandler:function(handler,target,cursor){ // 注册鼠标移动的一些事件。               var _IsMousedown=false,_ClickLeft=0,_ClickTop=0;               var _hDom=this.get(handler);               var _tDom=this.get(target);               _hDom.style.cursor=cursor||"move";               function startDrag(evt){ // 按下鼠标左键时的事件。                   evt=window.event||evt;    // 获取当前事件对象。                   _IsMousedown=true;    // 记录已经准备开始移动了。                   _ClickLeft=evt.clientX-parseInt(_tDom.style.left); // 记录当前坐标轴。                   _ClickTop=evt.clientY-parseInt(_tDom.style.top);               }               function doDrag(evt){ // 鼠标开始移动时的事件。                   evt=window.event||evt; // 获取当前事件对象。                   if(!_IsMousedown)return false; // 如果_IsMousedown不等于真了返回。                   _tDom.style.left=evt.clientX-_ClickLeft+"px"; // 把鼠标当前移动的位置赋值给div                   _tDom.style.top=evt.clientY-_ClickTop+"px"; // 当前位置减去开始位置就是层当前存放的位置。               }               function endDrag(){ // 释放鼠标左键时的事件。                   if(_IsMousedown){ // 如果_IsMousedown还为真那么就赋值为假。                       if(this.isIE) _tDom.releaseCapture(); //该函数从当前的窗口释放鼠标捕获,并恢复通常的鼠标输入处理。
首页 1 2 3 4 下一页