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();  
         }  
         }  
          
         }  
    
  • 相关阅读:
    [Luogu] 封锁阳光大学
    [other] Div
    [USACO11DEC] 牧草种植Grass Planting
    [Luogu] 仓鼠找sugar
    [USACO15DEC]最大流Max Flow
    [noip-2013] 货车运输
    [模板] 普通平衡树
    [Luogu] 树链剖分
    [ZJOI2008] 树的统计Count
    大组合数取模
  • 原文地址:https://www.cnblogs.com/luscinia/p/4177823.html
Copyright © 2011-2022 走看看