首页 > 代码库 > assets文件夹下文件目录复制到SD卡下
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(); } } }
assets文件夹下文件目录复制到SD卡下
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。