简体   繁体   English

有关Android应用中Runtime.getRuntime()。exec()命令用法的帮助

[英]Help regarding Runtime.getRuntime().exec() command usage in Android app

I am trying to make use of Runtime.getRuntime.exec() command to copy a folder from one location to another on sdcard. 我试图利用Runtime.getRuntime.exec()命令将文件夹从一个位置复制到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/ 下面是我试图将内容从/ sdcard / etc / data复制到/ sdcard / etc / temp /的代码片段

try { Process process = Runtime.getRuntime().exec("cp -r /sdcard/etc/ data /sdcard/etc/temp"); 尝试{处理过程= Runtime.getRuntime()。exec(“ cp -r / sdcard / etc / data / sdcard / etc / temp”); }catch (IOException e) { e.printStackTrace(); }捕获(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"); 尝试{处理过程= Runtime.getRuntime()。exec(“ ln -s / sdcard / etc / data / sdcard / etc / temp / data”); }catch (IOException e) { e.printStackTrace(); }捕获(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.. 谢谢,尼克。

You probably still need to have the WRITE_EXTERNAL_STORAGE permission, in case you do not have that. 如果没有的WRITE_EXTERNAL_STORAGE ,您可能仍需要具有WRITE_EXTERNAL_STORAGE权限。

Your bigger problem is that cp is not in any sort of PATH . 您更大的问题是cp不在任何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. 实际上,尽管我没有进行详尽的搜索,但在Android 2.2模拟器上的任何地方都看不到cp命令。

The way a savvy programmer would solve this is using Java , since that eliminates your dependency on undocumented/unsupported command-line binaries. 精明的程序员可以使用Java解决此问题,因为这消除了您对未记录/不支持的命令行二进制文件的依赖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Runtime.getRuntime()。exec - Android Runtime.getRuntime().exec 如何在Runtime.getRuntime()。exec()android中正确运行iperf命令 - How to run iperf command properly in Runtime.getRuntime().exec() android Android Runtime.getRuntime().exec 命令导致应用程序在获取 output 之前冻结 - Android Runtime.getRuntime().exec command causes app to freeze before getting an output Runtime.getRuntime()。exec无法在Android上启动所需的应用程序 - Runtime.getRuntime().exec not launching desired app on Android Android对Runtime.getRuntime()。exec()的权限 - Android Permissions on Runtime.getRuntime().exec() Java Android Runtime.getRuntime().exec() - Java Android Runtime.getRuntime().exec() Android Runtime.getRuntime()。exec和rsync - Android Runtime.getRuntime().exec and rsync Android-交互式外壳程序(Runtime.getRuntime()。exec()) - Android - Interactive shell (Runtime.getRuntime().exec()) 使用Runtime.getRuntime()。exec()在Android上执行“状态”时出现IOException吗? - IOException when using Runtime.getRuntime().exec() to exec “stat” on Android? Android:Runtime.getRuntime().exec(String) 命令太慢? 还是我做错了什么? - Android: Runtime.getRuntime().exec(String) command is too slow? or I am doing something wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM