Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

downloading mp3 from stream  RSS feed

Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
can some tell me what im doing wrong here im trying to execute this code using AsyncTask but i can't seem to getting to work. here is the code

class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
           protected Long doInBackground(URL... urls) {
               try {

                   URLConnection conn = new URL("").openConnection();
                   InputStream is = conn.getInputStream();

                   OutputStream outstream = new FileOutputStream(new File("/mnt/sdcard/Download/file.mp3"));
                   byte[] buffer = new byte[4096];
                   int len;
                   while ((len = > 0) {
                       outstream.write(buffer, 0, len);
               } catch (IOException e) {


       new DownloadFilesTask().execute();
Saloon Keeper
Posts: 5133
  • Mark post as helpful
  • send pies
  • Report post to moderator
What does the code do, and what should it be doing instead? Where does the observed behavior start to deviate from the expected behavior?
Posts: 21558
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Related to
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!