以编程方式将/system/app/*.apk 复制到 sdcard [英] Copy /system/app/*.apk to sdcard programmatically
本文介绍了以编程方式将/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)
它不起作用,谢谢
推荐答案
您似乎正在尝试将文件复制到文件夹,但没有指定目标文件名.
It looks like you're trying to copy a file to a folder, but without specifying the destination file name.
我猜您想将文件名附加到目标路径:
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屋!
查看全文