读书人

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

发布时间: 2012-10-05 15:34:33 作者: rapoo

把资源文件读到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();
}

}


}
}

读书人网 >移动开发

热点推荐