Android AsyncTask致命异常#1

Android AsyncTask致命异常#1,android,android-asynctask,Android,Android Asynctask,我有一个异步任务,它使用通道将文本文件下载到本地文件 class getUrlsClass extends AsyncTask<String, Integer, File>{ @Override protected File doInBackground(String... params) { URLConnection uc; File urlFiles= new File(getApplicationContext().getFi

我有一个异步任务,它使用通道将文本文件下载到本地文件

class getUrlsClass extends AsyncTask<String, Integer, File>{

    @Override
    protected File doInBackground(String... params) {
        URLConnection uc;
        File urlFiles= new File(getApplicationContext().getFilesDir(), "urls");
        try {
            URL url = new URL(params[0]);
            uc = url.openConnection();
            uc.setUseCaches(false);
            ReadableByteChannel rbc = Channels.newChannel(uc.getInputStream());
            FileOutputStream fos = new FileOutputStream(urlFiles);
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            fos.close();


        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

}

任务有什么问题?

异常是在以下位置引起的:

fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
因为参数
计数
不能大于
整数.MAX\u值
。这导致了这个特殊的异常

FileChannelImpl
类文件中找到:

    if (position < 0 || count < 0 || count > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("position=" + position + " count=" + count);
    }
if(位置<0 | |计数<0 | |计数>整数最大值){
抛出新的IllegalArgumentException(“position=“+position+”count=“+count”);
}

希望有帮助!:)

我假设您在清单中使用了
互联网
权限。能否请您调试fos.getChannel().transferFrom(rbc,0,Long.MAX_值)行并告诉
rbc
它是
java.nio.channels.channels的值$InputStreamChannel@95e1fd08
@Anand
    if (position < 0 || count < 0 || count > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("position=" + position + " count=" + count);
    }