📄 myclass.java~11~
字号:
package mythead;import java.net.*;import java.io.*;import javax.swing.*;public class myClass extends Thread { String sURL; long nStartPos; long nEndPos; int i; public static int theFileLength; RandomAccessFile dst ; public static int nowDownLength; public static JProgressBar jProgressBar1; myClass(String url,RandomAccessFile f,long start, long end,int i,int theFileLength,JProgressBar jProgressBar1) { this.sURL = url; this.dst =f; this.nStartPos = start; this.nEndPos = end; this.i=i; this.theFileLength=theFileLength; this.jProgressBar1=jProgressBar1; } public void run() { try { URL url = new URL(sURL); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setRequestProperty("RANGE", "bytes=" + nStartPos + "-"); InputStream input = httpConnection.getInputStream(); byte[] b = new byte[1024]; int nRead; this.currentThread().setName(""+this.i); while ( (nRead = input.read(b, 0, 1024)) > 0 && nStartPos < nEndPos) { dst.seek(nStartPos); dst.write(b, 0, nRead); myClass.nowDownLength=myClass.nowDownLength+nRead; nStartPos = nStartPos + nRead; System.out.println(""+this.currentThread().getName()+myClass.nowDownLength); myClass.jProgressBar1.setValue(myClass.nowDownLength/myClass.theFileLength*100); } } catch (Exception ex) { ex.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -