使用Java从SD卡中提取android文件
我想从 android SD 卡(模拟器或设备)中提取文件并将其放在我的 C:\ 驱动器上。
我怎样才能在Java中做到这一点?在命令提示符中,我只需键入:
C:\Users\ME\android-sdks\platform-tools\adb.exe 拉 /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,拉, /sdcard/test_1329402481933.jpg,c:]工作目录:空 环境:空于 java.lang.ProcessManager.exec(ProcessManager.java:196) 在 java.lang.Runtime.exec(Runtime.java:225) 在 java.lang.Runtime.exec(Runtime.java:313) 在 java.lang.Runtime.exec(Runtime.java:246) 在 com.blinkbox.client.test.MyTest.takeScreenShot(MyTest.java:138) 在 com.blinkbox.client.test.MyTest.testCanOpenSettings(MyTest.java:66) 在 java.lang.reflect.Method.invokeNative(本机方法) 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:权限被拒绝 java.lang.ProcessManager.exec(本机方法) at java.lang.ProcessManager.exec(ProcessManager.java:194) ... 19 更多
我愿意以完全不同的方式来做...只需要完成工作:)
I want to pull a file from the android SD card (emulator or device) and put it on my C:\ drive.
How can I do this in Java? in the command prompt, I simply type:
C:\Users\ME\android-sdks\platform-tools\adb.exe pull
/sdcard/test_1329402481933.jpg c:\
So in Java, I thought it would be something like:
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);
but, it fails giving me this trace:
java.io.IOException: Error running exec(). Commands:
[C:\Users\ME\android-sdks\platform-tools\adb.exe, pull,
/sdcard/test_1329402481933.jpg, c:] Working Directory: null
Environment: null at
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
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)
at
android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at
android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:175)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
at
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.io.IOException: Permission denied at
java.lang.ProcessManager.exec(Native Method) at
java.lang.ProcessManager.exec(ProcessManager.java:194) ... 19 more
I am open to do it an entirely different way... Just need to get the job done :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案 1:我认为线索是权限被拒绝
尝试写入不同的目录。
答案 2:尝试“cmd /c ...”
ANSWER 1: I think the clue there is Permission denied
Try writing to a different directory.
ANSWER 2: Try "cmd /c ..."
从堆栈跟踪 [AndroidTestRunner] 假设您通过 ide 启动它。尝试以管理员身份启动您的IDE,看看是否是这个问题。
From the stacktrace [AndroidTestRunner] asume you start it via ide. Try to start your ide as Administrator to find out if this is the problem.