我创建了一个asynctask
类以从网络上下载文件。
这是我的课:
private class DownloadFile1 extends AsyncTask<String, Integer, String> {
private boolean done = false;
@Override
protected String doInBackground(String... sUrl) {
done = false;
if (isOnline() == true && sdmounted() == true) {
try {
URL url = new URL(sUrl[0]); // get url
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream in = new BufferedInputStream(connection.getInputStream());
// url[1]= file name
OutputStream out = (downloaded == 0) ? new FileOutputStream("/sdcard/Points.ir/" + sUrl[1])
: new FileOutputStream("/sdcard/Points.ir/"
+ sUrl[1], true);
OutputStream output = new BufferedOutputStream(out, 1024);
byte[] data = new byte[1024];
int count = 0;
while (done != true && isOnline() == true && (count = in.read(data, 0, 1024)) >= 0) {
output.write(data, 0, count);
downloaded += count;
}
output.flush();
output.close();
in.close();
} catch (Exception e) {
}
} else {
networkerror = 1;
}
return null;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... progress)
{
super.onProgressUpdate(progress);
}
@Override
protected void onPostExecute(String result)
{
super.onPostExecute(result);
}
}
当我创建此类的对象并执行时,一切正常。但是当创建 2 个对象并同时执行下载 2 个文件时,它会得到 FC ?? 我该怎么办?(对不起我的英语不好)