How i can download server file with server user name and password
<p>There is username and password on my server acess , and i have a code for downloding server file without any            Username and password can u tell me what  modification is required to downlode server file with username and password </p>

<pre><code>  import java.io.BufferedInputStream;

    import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.OutputStream;
 import java.net.URL;
  import java.net.URLConnection;
  import java.util.PropertyPermission;

import android.os.AsyncTask;
 import android.os.Bundle;
 import android.app.Activity;
 import android.app.ProgressDialog;
 import android.view.Menu;

 public class DownloadFile extends Activity {



ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    System.out.println("1");

    //mProgressDialog = (ProgressDialog)findViewById(R.id.progressBar1);

    // instantiate it within the onCreate method

    mProgressDialog = new ProgressDialog(DownloadFile.this);
System.out.println("2");
    mProgressDialog.setMessage("A message");
    mProgressDialog.setIndeterminate(false);
    mProgressDialog.setMax(100);
    mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    // execute this when the downloader must be fired
    Download Download = new Download();

    System.out.println("3");
    Download.execute("http://111.118.182.xxx:xxxx/code/18.txt");
    System.out.println("4");
}





private class Download extends AsyncTask&lt;String, Integer, String&gt; {
    @Override
    protected String doInBackground(String... sUrl) {
        try {
            URL url = new URL("http://111.118.182.xxx:xxxx/code/18.txt");
            URLConnection connection = url.openConnection();
            connection.connect();
            // this will be useful so that you can show a typical 0-100% progress bar
            int fileLength = connection.getContentLength();

            // download the file
            InputStream input = new BufferedInputStream(url.openStream());
            System.out.println("8");
            OutputStream output = new FileOutputStream("/sdcard/18.txt");
               System.out.println("9");
            byte data[] = new byte[1024];
            long total = 0;
            int count;
            while ((count = input.read(data)) != -1) {
                total += count;

                // publishing the progress....
                publishProgress((int) (total * 100 / fileLength));
                output.write(data, 0, count);
            }

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

        System.out.println("7");
        return null;
    }


   }}
</code></pre>
