码迷,mamicode.com
首页 > 其他好文 > 详细

assets文件夹下文件目录复制到SD卡下

时间:2014-12-22 12:30:31      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

    private void copyDir(String path) {  
      
     String[] files;  
     try {  
     files = this.getAssets().list(path);  
     if (files.length == 0) {  
     copyFile(path);  
     } else {  
     String filePath = "mnt/sdcard" + "/" + path;  
     File file = new File(filePath);  
     file.mkdirs();  
     for (int i = 0; i < files.length; i++) {  
     String[] files2 = this.getAssets().list(path+"/"+files[i]);  
     if (files2.length == 0) {  
     copyFile(path + "/" + files[i]);  
     } else {  
     copyDir(path + "/" + files[i]);  
     }  
     }  
      
     }  
      
     } catch (IOException e) {  
     // TODO Auto-generated catch block  
     e.printStackTrace();  
     }  
      
     }  
      
    private void copyFile(String path) {  
     Log.v("file", path);  
     InputStream in = null;  
     FileOutputStream out = null;  
     try {  
      
     String filePath = "mnt/sdcard" + "/" + path;  
      
     File file = new File(filePath);  
      
     if (!file.exists()) {  
     in = this.getAssets().open(path);  
     out = new FileOutputStream(file);  
     int length = -1;  
     byte[] buf = new byte[1024];  
     while ((length = in.read(buf)) != -1) {  
     out.write(buf, 0, length);  
     }  
     out.flush();  
     in.close();  
     out.close();  
     }  
     } catch (IOException e) {  
     e.printStackTrace();  
    } finally {  
     try {  
     if (in != null) {  
     in.close();  
     }  
     if (out != null) {  
     out.close();  
     }  
     } catch (IOException e) {  
     e.printStackTrace();  
     }  
     }  
      
     }  

 

assets文件夹下文件目录复制到SD卡下

标签:

原文地址:http://www.cnblogs.com/luscinia/p/4177823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!