zoukankan      html  css  js  c++  java
  • assets文件夹下文件目录复制到SD卡下

        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();  
         }  
         }  
          
         }  
    
  • 相关阅读:
    JavaScript闭包基本概念
    JavaScript函数
    JavaScript类型比较
    Java思维导图之Class对象
    Python进阶之装饰器
    Java IO学习要点导图
    sl003完全平方数
    sl002个税计算
    sl001数字拼接
    装饰器
  • 原文地址:https://www.cnblogs.com/luscinia/p/4177823.html
Copyright © 2011-2022 走看看