2 maiyuqiang maiyuqiang 于 2016.09.24 11:58 提问

Android文件下载出现问题 20C

                        HttpClient client = new DefaultHttpClient();
                        HttpGet get = new HttpGet(downloadurl);
                        HttpResponse response;
                        try {
                            response = client.execute(get);
                            HttpEntity entity = response.getEntity();
                            long length = entity.getContentLength();
                            InputStream is = entity.getContent();
                            FileOutputStream fileOutputStream = null;
                            if (is != null) {
                                File file = new File(Environment
                                        .getExternalStorageDirectory(),
                                        fileName);
                                fileOutputStream = new FileOutputStream(file);
                                byte[] buf = new byte[1024];

                                int ch = -1;
                                int count = 0;
                                int percent = 0;
                                while ((ch = is.read(buf)) != -1) {
                                    fileOutputStream.write(buf, 0, ch);
                                    count += ch;
                                    if (((int) (100 * count / length)) > percent) {
                                        percent = (int) (100 * count / length);
                                        progressDialog.setProgress(percent);
                                        if (percent == 100) {
                                            successDownload = true;
                                        }
                                    }
                                    if (length > 0) {
                                    }
                                }
                            }
                            fileOutputStream.flush();
                            if (fileOutputStream != null) {
                                fileOutputStream.close();
                            }
                            down(fileName);
                        } catch (ClientProtocolException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                            progressDialog.cancel();

                        }

之前的下载地址是文件路径,可以下载,后来改成我给后台发请求后下载,这样下载就不行了,这个应该怎么改?

1个回答

itworkermk
itworkermk   2016.09.24 17:38

后台请求的下载?什么鬼?
你看看能不能直接在网页下载或者 找到指定文件路径
再有 下载为毛自己写 那么多封装的很好的控件 重复 造轮子

Csdn user default icon
上传中...
上传图片
插入图片