0

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Why would you possibly want the "cp" command, when "cat" can do everything you need? :-)
In my opinion using cp is much easier to learn than the java aspect. That and I use it for root commands. It's not in stock Android (as far as I know). Your phone must have Busybox installed (and generally be rooted).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.