views:

53

answers:

1

Hi All,

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..

+1  A: 

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.

CommonsWare
Why would you possibly want the "cp" command, when "cat" can do everything you need? :-)
fadden