Android creates folders and files and installs other apk files

Source: Internet
Author: User

1. Create a folder in android

File sd=Environment.getExternalStorageDirectory();        String path=sd.getPath()+"/notes";        File file=new File(path);        if(!file.exists())           file.mkdir();

2. Create a file in 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 FileOutputStream defines the file, you can use the. write method to write the content to create the corresponding file.

3. install other apk for android

                        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);


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.