首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2012-10-05 
把资源文件读到sd卡目录下public class ActivityMain extends Activity {public void onCreate(Bundle sav

把资源文件读到sd卡目录下
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[1024];
       
        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();
}
       
        }
       
       
    }
}

热点排行