Reputation: 61
I am trying to make use of Runtime.getRuntime.exec() command to copy a folder from one location to another on sdcard. But it seems like it doesn't work
Below is the code snippet where I am trying to copy the contents from / sdcard/etc/data to /sdcard/etc/temp/
try { Process process = Runtime.getRuntime().exec("cp -r /sdcard/etc/ data /sdcard/etc/temp"); }catch (IOException e) { e.printStackTrace(); }
I also tried creating a soft link as an alternative.. Event that did not work.
try { Process process = Runtime.getRuntime().exec("ln -s /sdcard/etc/ data /sdcard/etc/temp/data"); }catch (IOException e) { e.printStackTrace(); }
Could someone please help me on this. Am I using the Runtime in the proper way if not could you please suggest me an alternative.. Appreciate your help!
Thanks, Nik..
Upvotes: 0
Views: 2494
Reputation: 1006869
You probably still need to have the WRITE_EXTERNAL_STORAGE
permission, in case you do not have that.
Your bigger problem is that cp
is not in any sort of PATH
. In fact, I do not see the cp
command anywhere on the Android 2.2 emulator, though I have not done an exhaustive search.
The way a savvy programmer would solve this is using Java, since that eliminates your dependency on undocumented/unsupported command-line binaries.
Upvotes: 2