Hi All,

The following is the code that am using to download a file from the
web server on android mobile,

imageURL="http://rokon.googlecode.com/files/rokon_src_2-0-3.zip";;


try {
                URL url = new URL(imageURL); //you can write here any
link

                File file = new File(fileName);

                long startTime = System.currentTimeMillis();
                Log.i("DownloadManager", "download begining");
                Log.i("DownloadManager", "download url:" + url);
                Log.i("DownloadManager", "downloaded file name:" +
fileName);


                /* Open a connection to that URL. */

                URLConnection ucon = url.openConnection();

                /*
                 * Define InputStreams to read from the URLConnection.
                 *
                 */

                InputStream is = ucon.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is);

                /*
                 * Read bytes to the Buffer until there is nothing
more to read(-1).
                 */

                ByteArrayBuffer baf = new ByteArrayBuffer(50);
                int current = 0;
                while ((current = bis.read()) != -1) {
                        baf.append((byte) current);
                }



                /* Convert the Bytes read to a String. */

                FileOutputStream fos = new FileOutputStream(PATH
+file);
                fos.write(baf.toByteArray());
                fos.close();
                Log.i("DownloadManager", "download ready in" +
((System.currentTimeMillis() - startTime) / 1000)+ " sec");

        }
        catch (IOException e) {
                Log.e("DownloadManager", "IOException: " + e);
        }
        catch(Exception ex)
        {
                Log.e("DownloadManager", "Exception: " + ex);
        }

this code is working fine for the above imageURL string, but when i
replace the url with the web server that am accessing then it is
giving problem. can anyone help me in this..

Thanks&Regards.

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to