以编程方式将/system/app/*.apk复制到sdcard [英] Copy /system/app/*.apk to sdcard programmatically

查看:185
本文介绍了以编程方式将/system/app/*.apk复制到sdcard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个apk的路径/system/app/Gallery2.apk,我想在sdcard上复制这个。我实现复制方法

i have path of one apk "/system/app/Gallery2.apk" and i want to copy this on sdcard. i implement copy method

 public void copy(File src, File dst) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dst);

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

但它显示IOException

but it shows IOException

我传递值

 try {
                    File file =new File( pm.getApplicationInfo(TAG_PACKAGE.get(position),PackageManager.GET_META_DATA).publicSourceDir);

                    Toast.makeText(MainActivity.this , pm.getApplicationInfo(TAG_PACKAGE.get(position),PackageManager.GET_META_DATA).publicSourceDir, Toast.LENGTH_LONG).show();

                try {
                    File dir = new File(Environment.getExternalStorageDirectory() + "/foldername/");
                     if(!dir.exists())
                        {
                            if(dir.mkdir()) ;//directory is created;
                            Toast.makeText(MainActivity.this ,dir.toString(), Toast.LENGTH_LONG).show();

                        }

                     copy(file.getAbsoluteFile(), dir);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                } catch (NameNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

例外:

  exception java.io.FileNotFoundException: /storage/sdcard0/folder: open failed: EISDIR (Is a directory)

它不工作,thnks

it is not working , thnks

推荐答案

我想要将文件名追加到目标路径:

I guess you want to append the file name to the destination path :

copy(file.getAbsoluteFile(), new File(dir, file.getName()));

这篇关于以编程方式将/system/app/*.apk复制到sdcard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆