下载mp3文件时意外结束流错误

时间:2013-10-28 12:16:02

标签: android

下载mp3文件时出现意外的流错误结束。 有时下载音量然后显示意外的流错误结束。 我阅读了网站rss(XML_TAGS)的链接。

URLConnection conection = url.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();

InputStream input = new BufferedInputStream(url.openStream(),8192);

File directory = new File("/storage/sdcard/Music/");
directory.mkdir();
// Create MusicDir
File mypath = new File(directory, "profile.mp3");

// Output stream
OutputStream output = new FileOutputStream(mypath);

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lenghtOfFile));

// writing data to file
output.write(data, 0, count);0, count);

0 个答案:

没有答案
相关问题