下载 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);