gpt4 book ai didi

android - 以编程方式复制/system/app/*.apk 到 sdcard

转载 作者:行者123 更新时间:2023-11-29 01:49:18 29 4
gpt4 key购买 nike

我有一个 apk 的路径“/system/app/Gallery2.apk”,我想将其复制到 sdcard 上。我实现复制方法

 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

我传递值

 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

最佳答案

看起来您正在尝试将文件复制到文件夹,但没有指定目标文件名。

我猜您想将文件名附加到目标路径:

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

关于android - 以编程方式复制/system/app/*.apk 到 sdcard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19311690/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com