下面这段代码在程序中运行出现IOException
/**
* 下载线程
*/
private Runnable runnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
URL url = new URL(apkUrl);
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.connect();
int length = conn.getContentLength();
InputStream is = conn.getInputStream();
File file = new File(savePath);
if (!file.exists()) {
file.mkdir();
}
String apkFile = saveFileName;
File ApkFile = new File(apkFile);
FileOutputStream fos = new FileOutputStream(ApkFile);
int count = 0;
byte buf[] = new byte[1024];
do {
int numread = is.read(buf);
count += numread;
progress = (int) (((float) count / length) * 100);
// 更新进度条
mHandler.sendEmptyMessage(DOWN_UPDATE);
if (numread <= 0) {
// 下载完