Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android創建文件夾和文件和安裝其他apk

android創建文件夾和文件和安裝其他apk

編輯:關於Android編程

一、android下創建文件夾

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

二、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 ;
					        	
					   
					    	    }
					        }
FileOutputStream定義文件後,用.write方法寫入內容,就可以創建對應文件了。

三、android安裝其他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);


  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved