使用
- 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/");
------解决方案--------------------