首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从安卓SD卡服务器下载MP3文件

从安卓SD卡服务器下载MP3文件
EN

Stack Overflow用户
提问于 2015-10-10 15:58:09
回答 1查看 230关注 0票数 0

我想从服务器上逐个下载所有的mp3文件并保存到SD卡文件夹中。我没有任何错误或异常,但mp3没有下载,也没有显示在SD卡中。有没有人能帮我解决这个issue.Here是我的代码。

代码语言:javascript
运行
复制
if (imageName.endsWith(mp3_Pattern))
                    {
                        str_DownLoadUrl = namespace + "/DownloadFile/FileName/" + imageName;

                        Log.e("#########  ", "str_DownLoadUrl  = " + str_DownLoadUrl);
                        download_Mp3File(str_DownLoadUrl);

                        strDownLoadStatus = "1";
                        dbhelper.update_DownLoadStatus(imageName, strDownLoadStatus);
                    }

 void download_Mp3File(final String fileUrl) {

        new AsyncTask<String, Integer, String>()
        {
            @Override
            protected String doInBackground(String... arg0)
            {
                int count;
                File file = new File(newFolder, System.currentTimeMillis() + imageName);
                try
                {
                    URL url = new URL(fileUrl);
                    URLConnection conexion = url.openConnection();
                    conexion.connect();
                    // this will be useful so that you can show a tipical 0-100% progress bar
                    int lenghtOfFile = conexion.getContentLength();

                    // downlod the file
                    InputStream input = new BufferedInputStream(url.openStream());
                    OutputStream output = new FileOutputStream(file);

                    byte data[] = new byte[1024];

                    long total = 0;

                    while ((count = input.read(data)) != -1) {
                        total += count;
                        // publishing the progress....
                        publishProgress((int) (total * 100 / lenghtOfFile));
                        output.write(data, 0, count);
                    }

                    output.flush();
                    output.close();
                    input.close();
                } catch (Exception e) {
                }
                return  null;
            }
        }.execute();

    }
EN

回答 1

Stack Overflow用户

发布于 2015-10-10 16:10:02

在inputstream对象中放置一个断点来查看是否有流。然后调试输出流以查看结果。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33051716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档