Hi
I want to down load one .apk file to my SDcard from the URL,
but I got error when i want to create the file, if any body know the problem
can you please help me,
my code crash on the red line,

my code is

public class download extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       final int mode=this.MODE_PRIVATE;
        setContentView(R.layout.main);
        final Button btn=(Button)findViewById(R.id.Button01);
        btn.setOnClickListener(new Button.OnClickListener() {
              public void onClick(View v) {
                  try{
                  URL sourceUrl = new URL("
http://www.androidfreeware.org/getfile/OperaMini_4.0.apk";);
                  HttpURLConnection conn=
(HttpURLConnection)sourceUrl.openConnection();
                  conn.setDoInput(true);
                  conn.connect();
                  InputStream is = conn.getInputStream();
                  FileOutputStream fos = openFileOutput("/sdcard/mahsa.apk",
mode);
                  int read = 0;
                  byte[] buffer = new byte[512];
                  BufferedInputStream bis = new BufferedInputStream(is);
                  do{
                       read = bis.read(buffer);
                       if(read > 0){
                            fos.write(buffer, 0, read);
                       }
                  }while(read != -1);
              }catch (Exception e) {
            Log.e("error", "bad application");
            }
                   }

              });


        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to