参考文章
批量从assets复制文件到sd卡
[url]http://licongf18.blog.163.com/blog/static/155695482010102655746661/[/url]
我的代码
批量从assets复制文件到sd卡
[url]http://licongf18.blog.163.com/blog/static/155695482010102655746661/[/url]
我的代码
//调用代码
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();
}
}
本文介绍了一个简单的Android应用程序功能,用于将资源文件从应用的assets目录复制到设备的SD卡上。通过提供的Java代码示例,开发者可以了解如何实现这一过程,并处理可能出现的异常情况。
2581

被折叠的 条评论
为什么被折叠?



