First, create folders under Android
File sd=environment.getexternalstoragedirectory (); String Path=sd.getpath () + "/notes"; File File=new file (path); if (!file.exists ()) file.mkdir ();
II. create files under Android
HttpClient HttpClient = new Defaulthttpclient (); HttpGet httpget= New HttpGet ("http://img3.3lian.com/2006/016/09/031.jpg"); HttpResponse HttpResponse = Httpclient.execute (HttpGet), if (Httpresponse.getstatusline (). GetStatusCode () = = 200) { Total_length = Httpresponse.getentity (). Getcontentlength (); is = Httpresponse.getentity (). getcontent (); File File = new file (Environment.getexternalstoragedirectory (), "aupdata.jpg"); FOS = new FileOutputStream (file); bis = new Bufferedinputstream (IS); byte[] buffer = new byte[1024]; byte [] result_two = new byte [(int) total_length]; int len = 0; int total=0; while (len = bis.read (buffer)) >-1) {system.arraycopy (buffer, 0, Result_two, Total, Len); Fos.write (buffer, 0, Len); Total = Total + len; } }
After the FileOutputStream defines the file, you can create the corresponding file by writing it with the. Write method.
Third, Android install other APK
Intent Intent = new Intent (); intent.setaction (Intent.action_view); File Install_file = new file (Environment.getexternalstoragedirectory (), "myweb.apk"); Intent.setdataandtype ( Uri.fromfile (Install_file), "application/vnd.android.package-archive"); StartActivity (intent);