使用
Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
用上面的方法提示说权限不足我尝试了下用输入输出流先把assets的文件读入到输入流,再用输出流写到sdcard中,这样是可以的,除此之外还有别的方法吗?如果文件多的话,这样作效率很低的
Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
用上面的方法提示说权限不足我尝试了下用输入输出流先把assets的文件读入到输入流,再用输出流写到sdcard中,这样是可以的,除此之外还有别的方法吗?如果文件多的话,这样作效率很低的
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 file = new File("/mnt/sdcard/filename");
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();
}
}
将路径写入了数据库,然后拷贝到sdcard上,最读sdcard里面的数据库信息就可以拉
但是Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
这个命令是linux命令
你可以试试Runtime.getRuntime().exec("cp assets/* /mnt/sdcard/images/");
Runtime.getRuntime().exec("cp /data/data/apk的包名/res/assets/* /mnt/sdcard/images/");