从安卓应用中解压数据到sdcard卡中

来源:互联网 发布:算法书籍 编辑:程序博客网 时间:2024/05/16 07:11

>基本思路:

首先,到你安卓工程目录下的res文件夹中创建一个raw文件夹,然后利用getResources()方法获取输入源,并通过FileOuoutStream方法写出到已存在的指定sdcard目录下。


>样例代码:

try{    Resources res = getResources();    InputStream is = res .openRawResource(R.raw.qwe);    FileOutputStream fos = new FileOutputStream(new File("/sdcard/MYclient/qwe.jpg"));    int len=0;    byte[] buf=new byte[1024];    while((len=is.read(buf))!=-1){        fos.write(buf,0,len);    }System.out.println("解压完毕");}catch (Exception e){    e.printStackTrace();}

原创粉丝点击