---
title: "把资源文件读到sd卡目录下"
author: "zhangle2612"
date: "2010-10-25T17:37:53Z"
tags: []
categories: ["移动开发"]
slug: "sd"
draft: false
lastmod: "2010-10-25T17:37:53Z"
id: 793491
url: "https://lowry.iteye.com/blog/793491"
---

public class ActivityMain extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        InputStream is = getResources().openRawResource(R.drawable.android);
        
        OutputStream ops = null;
        
        try{
        	ops = new FileOutputStream("/sdcard/a.jpg");
        
        	byte b = new byte;
        	
        	int len = -1;
        	while((len = is.read(b))!=-1){
        		ops.write(b, 0, len);      		
        	}
        	
        	ops.flush();
   	
        }catch(Exception e){  
        	e.printStackTrace();
        }
        finally{
        	try {
				is.close();
				ops.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
        	
        }
        
        
    }
}