📄 downloadthread.java
字号:
package cc;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class DownLoadThread extends Thread {
long[] start;
long[] end;
long filelength;
File file;
public DownLoadThread() {
file = new File("d:/jifdetuo.mp3");
start = new long[5];
end = new long[5];
}
public void run() {
filelength = getlength();
if (filelength == 0) {
System.out.println("error");
} else if (filelength == -2) {
System.out.println("error");
} else {
for (int i = 0; i < start.length; i++) {
start[i] = i * (filelength / start.length);
}
for (int i = 0; i < end.length - 1; i++) {
end[i] = start[i + 1];
}
end[end.length] = filelength;
}
}
private long getlength() {
URL url;
long filelength = 0;
try {
url = new URL("http://www.daqiancn.com/images/解脱.MP3 ");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Uer-Agent", "NetFox");
int responseCode = con.getResponseCode();
if (responseCode >= 400) {
return -2;
}
filelength = con.getContentLength();
} catch (IOException e) {
e.printStackTrace();
}
return filelength;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -