专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

将assets目录下的一些图片拷贝到sdcard中解决办法

发布时间:2010-05-30 10:55:38 文章来源:www.iduyao.cn 采编人员:星星草
将assets目录下的一些图片拷贝到sdcard中
使用

Java code

Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");



用上面的方法提示说权限不足

我尝试了下用输入输出流先把assets的文件读入到输入流,再用输出流写到sdcard中,这样是可以的,除此之外还有别的方法吗?如果文件多的话,这样作效率很低的

------解决方案--------------------
好像不可以,用IO流读写才行~~~
------解决方案--------------------
private void copyGloab2Databases() {
File file = new File("/data/data/" + getPackageName() + "/databases/",
Utils.GLOBALDB+".db");
file.getParentFile().mkdirs();
if(file.exists())
return;

InputStream in;
OutputStream out;
try {
in = getAssets().open(Utils.GLOBALDB+".db");
out = new FileOutputStream(file);

byte[] buff = new byte[1024];
int len;
while ((len = in.read(buff)) > 0) {
out.write(buff, 0, len);
}

out.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
------解决方案--------------------
file:///android_asset/*是用于java代码中调用assets目录下的所有文件
但是Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
这个命令是linux命令
你可以试试Runtime.getRuntime().exec("cp assets/* /mnt/sdcard/images/");
------解决方案--------------------
探讨

应该不可以的,看样子只能用读IO了
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: