使用
Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
用上面的方法提示说权限不足我尝试了下用输入输出流先把assets的文件读入到输入流,再用输出流写到sdcard中,这样是可以的,除此之外还有别的方法吗?如果文件多的话,这样作效率很低的

解决方案 »

  1.   

    这样如果assets下有好多小的文件要传入sdcard中,效率会很慢的
      

  2.   

    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();
    }
    }
      

  3.   

    private void copyGloab2Databases() {
    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();
    }
    }
      

  4.   

    多谢楼上提供方法
    将路径写入了数据库,然后拷贝到sdcard上,最读sdcard里面的数据库信息就可以拉
      

  5.   

    file:///android_asset/*是用于java代码中调用assets目录下的所有文件
    但是Runtime.getRuntime().exec("cp file:///android_asset/* /mnt/sdcard/images/");
    这个命令是linux命令
    你可以试试Runtime.getRuntime().exec("cp assets/* /mnt/sdcard/images/");
      

  6.   

    会报Error running exec(). Command: [cp, assets/*, /mnt/sdcard/images/] Working Directory: null Environment: null
      

  7.   

    那看来相对路径有问题
    Runtime.getRuntime().exec("cp /data/data/apk的包名/res/assets/* /mnt/sdcard/images/");