How to download xml file from web url
<p>I am new to Android Java, can anyone help me with this download?<br/>
This is what I'm trying.
Everytime i m running this app, it is shutting down immediately I press my download button, so is there a run time error in the following code?</p>

<pre class="lang-java prettyprint-override"><code>File xml;

private String down_file = "options.xml";
private Context context;
URL url;
URLConnection connection;
url  = new URL("http://sourceforge.net/projects/trialxml/files/options.xml");
xml  = new File(context.getCacheDir(), down_file);

try {
    connection = url.openConnection();
    connection.connect();
    InputStream stream = connection.getInputStream();
    if (stream == null) {
        Log.e(TAG, "uanble to create Input stream for the url" + url);
    }
    FileOutputStream fos = new FileOutputStream(xml);
    byte buf[] = new byte[128 * 1024];
    do {
        int numread = stream.read(buf);
        if (numread &lt;= 0) {
            break;
        } else {
            fos.write(numread);
        }
    } while (true);

    fos.close();
} catch(Exception e) {
    System.out.println("cannot download the xml file");
    e.printStackTrace();
}
</code></pre>
