首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

程序异常

2012-03-17 
程序错误以下是关于线程代码的内容和运行后提示如下异常:Exception in thread Thread-2 java.lang.Array

程序错误
以下是关于线程代码的内容和运行后提示如下异常:

Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: 0
at download.DownLoadThread.run(DownLoadThread.java:60)
自己是在无法解决,情大侠们帮忙解决下;


package download;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.swing.JOptionPane;

public class DownLoadThread extends Thread{



long DownLength = 0;//已下载文件大小

public void run() {
String url = DownloadNewFrm.getTxtAddress().getText();//获取url地址
String currentFileThreadName = DownloadNewFrm.txtSave.getText() + DownloadNewFrm.txtFile.getText();//完整路径名
InputStream in = null;
FileOutputStream out = null;

try {

URL Url = new URL(url);
HttpURLConnection httpConnection = (HttpURLConnection) (Url.openConnection());

in = httpConnection.getInputStream();
out = new FileOutputStream(currentFileThreadName);

int i = 0;
long nFileLength = DownloadNewFrm.getFileSize(); // 文件大小

while ((i = in.read()) != -1) {
out.write(i);// 写文件
DownLength ++;
long num = DownLength * 100L/nFileLength;
MultiDownloaderFrm.pgbRate.setValue((int)num);
//MultiDownloaderFrm.getTxaSpeedSize().setText("" + DownLength/1024 + "KB");
}



int threadNum = Integer.parseInt(MultiDownloaderFrm.txaSwing.getText());
long block = nFileLength/threadNum;
DownLoadThread[] downThreads = new DownLoadThread[0];
if(nFileLength%threadNum == 0) {
for(int j = 0; j < threadNum; j++) {
downThreads[j].DownLength=j*block;
downThreads[j].DownLength=block;
}
} else {
for(int j = 0; j < threadNum; j++) {
downThreads[j].DownLength=j*block;
downThreads[j].DownLength=block;
}
downThreads[0].DownLength = block - nFileLength%threadNum;
}
}catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
in.close();
out.close();

} catch (IOException e1) {
e1.printStackTrace();
}

}
}

}








[解决办法]

热点排行
Bad Request.