当前位置:操作系统 > 安卓/Android >>

将应用raw里的文件copy到sd卡实现

把APK的资源文件copy到SD卡下的实现。
[html]        /* 
 * 将raw里的文件copy到sd卡下 
 * */ 
public void copyResToSdcard(String name){//name为sd卡下制定的路径 
     Field[] raw = R.raw.class.getFields(); 
    for (Field r : raw) { 
         try { 
        //     System.out.println("R.raw." + r.getName()); 
             int id=getResources().getIdentifier(r.getName(), "raw", getPackageName()); 
               if(!r.getName().equals("allapps")){ 
                     String path=name+"/"+r.getName()+".png"; 
                 BufferedOutputStream bufEcrivain = new BufferedOutputStream((new FileOutputStream(new File(path)))); 
                 BufferedInputStream VideoReader = new BufferedInputStream(getResources().openRawResource(id)); 
                 byte[] buff = new byte[20*1024]; 
                 int len; 
                 while( (len = VideoReader.read(buff)) > 0 ){ 
                     bufEcrivain.write(buff,0,len); 
                 } 
                 bufEcrivain.flush(); 
                 bufEcrivain.close(); 
                 VideoReader.close(); 
               } 
         } catch (Exception e) { 
             e.printStackTrace(); 
         } 
     } 
     



摘自 agods--足迹
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,