我想从android SD卡(模拟器或设备)中提取文件并将其放在我的C:\驱动器上。
我怎样才能用Java做到这一点?在命令提示符中,我只需输入:
C:\ Users \ ME \ android-sdks \ platform-tools \ adb.exe pull /sdcard/test_1329402481933.jpg c:\
所以在Java中,我认为它会是这样的:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("C:\\Users\\ME\\android-sdks\\platform-tools\\adb.exe pull /sdcard/test_1329402481933.jpg c:\\");
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
但是,它没有给我这个痕迹:
java.io.IOException:运行exec()时出错。命令: [C:\ Users \ ME \ android-sdks \ platform-tools \ adb.exe,pull, /sdcard/test_1329402481933.jpg,c:]工作目录:null 环境:null java.lang.ProcessManager.exec(ProcessManager.java:196)at java.lang.Runtime.exec(Runtime.java:225)at java.lang.Runtime.exec(Runtime.java:313)at java.lang.Runtime.exec(Runtime.java:246)at com.blinkbox.client.test.MyTest.takeScreenShot(MyTest.java:138)at at com.blinkbox.client.test.MyTest.testCanOpenSettings(MyTest.java:66)at java.lang.reflect.Method.invokeNative(Native Method)at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205) 在 android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195) 在 android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:175) 在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
在android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) 在 android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430) 在 android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1447) 引起:java.io.IOException:Permission denied at java.lang.ProcessManager.exec(Native Method)at java.lang.ProcessManager.exec(ProcessManager.java:194)... 19更多
我愿意以完全不同的方式做到这一点......只需要完成工作:)
答案 0 :(得分:2)
答案1:我认为线索有权限被拒绝
尝试写入其他目录。
答案2:尝试“cmd / c ...”
String[] args = {"cmd", "/c", "\"C:\\Users\\ME\android-sdks\\platform-tools\\adb.exe pull /sdcard/test_1329402481933.jpg c:\\test\"",};
Runtime rt = Runtime.getRuntime();
ProcessBuilder pb = new ProcessBuilder(args);
Process pr = pb.start();
答案 1 :(得分:0)
Here is a way to pull a file from an Android. You will need to use ddmlib to find the device. import com.android.ddmlib.IDevice; import com.android.ddmlib.SyncService; void pullFile(IDevice device, String file, String remotePath, String localPath) { SyncService service = getSyncService(device); try { service.pullFile( remotePath + file , localPath + file , SyncService.getNullProgressMonitor()); } catch (SyncException | TimeoutException | IOException e) { log.error("pull " + file + ":" + e.getMessage()); } }
答案 2 :(得分:0)
从stacktrace [AndroidTestRunner]中,您可以通过ide启动它。尝试以管理员身份启动您的ide,以确定这是否是问题。