ITeye博客

把资源文件读到sd卡目录下

zhangle2612 · 2010-10-25 17:37 · Android · 移动开发 · Markdown

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

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。