我有一个 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)
它不工作,谢谢