I am trying to programmatically move files from internal memory in Android to an existing directory on an SD card.
I tried two ways. In the first, I used File.renameTo:
String destName = externalDirPath + File.separatorChar + destFileName;
File originFile = new File(cacheDirPath + File.separatorChar + originalfileName);
originFile.renameTo(new File(destName));
In another, I used Runtime.getRuntime ():
Process p = Runtime.getRuntime().exec("/system/bin/sh -");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
String command = "cp " + cacheDirPath + "/" + originalfileName+ " " + externalDirPath + "/" + destFileName+ "\n";
os.writeBytes(command);
They don’t work with both ..
Any suggestion?
source
share