我做的是下载工具,但当很网站连接下载是io流为什么老是说已关闭!
有是还抛有Exception.下面是一个 下载函数;提供下载调用。
performDownLoad();
}
public void performDownLoad(){
int byteCount;//一次输入流读的字节数;
Runnable progressUpdate = new Runnable(){
public void run(){
progressBar.setValue(bytesRead);
completeLabel.setText(Integer.toString(bytesRead));
}
};
                  //bytesRead 读入的全部字节数 stopped 控制停止的
while((bytesRead <= fileSize)&&(!stopped)){
try{
byteCount = inputStream.read(buffer);
if(byteCount == -1)
{
stopped = true;
break;
}
else {
outputStream.write(buffer,0,byteCount);
OutputStream.flush();
bytesRead += byteCount;
SwingUtilities.invokeLater(progressUpdate);
progressBar.setValue(bytesRead);
completeLabel.setText(Integer.toString(bytesRead)); 
}
}
catch(IOException ioe){
stopped = true ;
JOptionPane.showMessageDialog(this,ioe.getMessage(),"I/O error",
JOptionPane.ERROR_MESSAGE);
break;
}
try{
outputStream.close();
inputStream.close();
}
catch(IOException ioe){};
}
 }