Faisal,
You should be able to save the data retrieved from the URL connection
to a FileOutputStream.

e.g:

        FileOutputStream out = null;
        InputStream stream = null;
        File temp = null;
        try {
                long prod = 0l;
                        URL url = new URL(urlPath);
                        URLConnection cn = url.openConnection();
                        cn.connect();
                        stream = cn.getInputStream();
                        if (stream == null)  {
                                throw new RuntimeException("stream is null");
                        }
                        temp = new File("/sdcard/" + nameOfFile);
                        out = new FileOutputStream(temp);
                        byte buf[] = new byte[1024];
                        do {
                                int numread = stream.read(buf);
                                if (numread <= 0)
                                        break;
                                out.write(buf, 0, numread);
                                prod += numread;
                                updateDisplay(prod, false);
                        } while (true);
                } catch (Exception e) {
                        Log.e(APP_TAG, "error: " + e.getMessage(), e);
                } finally {
                        try {
                                out.close();
                        }
                        catch (Exception ex) {
                                Log.e(APP_TAG, "error: " + ex.getMessage(), ex);
                        }
                        try {
                                stream.close();
                        }
                        catch (Exception ex) {
                                Log.e(APP_TAG, "error: " + ex.getMessage(), ex);
                        }
                }

Oh, and make sure you've set up android.permission.READ_OWNER_DATA and
android.permission.WRITE_OWNER_DATA permissions in your
AndroidManifest.xml, of course.

Dave

On 10 Nov, 07:26, Faisal Abid <[EMAIL PROTECTED]> wrote:
> How would i Go about downloading a file and saving it to the sd card.
> I tried doing URL connection and i get the data of the file by how
> would i go about saving it now? Is there a better way then URL
> connection?
>
> Thanks, Faisal
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to