Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:41:14+00:00 2026-06-10T07:41:14+00:00

I have created a HTTP file server with the objective of transferring media files

  • 0

I have created a HTTP file server with the objective of transferring media files (mp3, ogg etc) to an Android device. When the server is accessed from the android browser like

10.0.2.2:portNumber/path/to/file

The server initiates the file download process. Of course the customer would not do such a thing, Its fine for testing the file server.
I m new to Android development and have learned that httpclient package can manage get/post requests. Here is the sample code I have been using for reading the response

DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
  HttpResponse execute = client.execute(httpGet);
  InputStream content = execute.getEntity().getContent();

  BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
  String s = "";
  while ((s = buffer.readLine()) != null) {
    response += s;
  }
} catch (Exception e) {
  e.printStackTrace();
}

return response;

The above code works fine when the server sends a list of file in JSON. Since the server part of sending file has been coded, the point where I m stuck is in retrieving the media file on android.

I m confused about how to receive the mp3 files send by the server. Should they be read in a stream ? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:41:15+00:00Added an answer on June 10, 2026 at 7:41 am

    Yes, you want to read the file onto disk via an inputstream.
    Here’s an example. If you don’t want a file download progress bar then remove the progress related code.

    try {
            File f = new File("yourfilename.mp3");
            if (f.exists()) {
                publishProgress(100,100);
            } else {
                int count;
                URL url = new URL("http://site:port/your/mp3file/here.mp3");
                URLConnection connection = url.openConnection();
                connection.connect();
                int lengthOfFile = connection.getContentLength();
                long total = 0;
                InputStream input = new BufferedInputStream(url.openStream());
                OutputStream output = new FileOutputStream(f);
                byte data[] = new byte[1024];
                while ((count = input.read(data)) != -1) {
                    total += count;
                    publishProgress((int)(total/1024),lengthOfFile/1024);
                    output.write(data, 0, count);
                }
                output.flush();
                output.close();
                input.close();
            }
        } catch (Exception e) {
            Log.e("Download Error: ", e.toString());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple HTTP server which allows users to download files. But
I have created http service on android. And now I want to upload the
I have created a simple flash menu and the SWF file, JS files (swfoject.js
I have created an Android application where I connect to a remote server php
I have created a simple http server for my family on the local network,
I'm using simple apache http linux mandriva server. I have created an ajax page
To explain my question I have created this http://jsfiddle.net/Jams/XNVB2/ here I want when div1
I am using IIS 6 on 2003. I have created a HTTP handler dll
I am using ASP MVC 2 and Nhibernate. I have created an HTTP Module
I have created the following demo: http://thedrivepartnership.com/overflow.html The scrolls expand fine in FireFox /

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.