`

从assets复制文件到sd卡

 
阅读更多
参考文章
批量从assets复制文件到sd卡
http://licongf18.blog.163.com/blog/static/155695482010102655746661/

我的代码
//调用代码
CopyAssets("/sdcard/xxx/", "xxx.txt");
private void CopyAssets(String dir, String fileName){
		//String[] files;
		File mWorkingPath = new File(dir);
		if (!mWorkingPath.exists()) {
			if (!mWorkingPath.mkdirs()) {
				Log.e("--CopyAssets--", "cannot create directory.");
			}
		}
		try {
			InputStream in = this.getResources().getAssets().open(fileName);
			System.err.println("");
			File outFile = new File(mWorkingPath, fileName);
			OutputStream out = new FileOutputStream(outFile);
			// Transfer bytes from in to out
			byte[] buf = new byte[1024];
			int len;
			while ((len = in.read(buf)) > 0) {
				out.write(buf, 0, len);
			}
			in.close();
			out.close();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics