我想手动添加一个 [文本] 文件到我的 Android 模拟设备,然后在我运行我的程序时将它作为文件检索。我在测试中可以访问自己C盘的文件,但是显然我无法在我的模拟器上访问我PC的C盘。 我可以在文件浏览器 [device].adk/data 上进入我的设备,文件夹列表是: - 应用程序 - 基准测试 -杂项 - native 测试
我尝试检索文件的方式是:
public static final String MY_FILE = "[directoryhere]";
我的问题是:我应该将我的文件存储在哪个文件夹中,我应该从哪个目录中检索它?
或者,我尝试将其存储在我的本地主机上并按以下方式访问目录:
public static final String MY_FILE = "http://[myip]/files/my.file";
但是,当我尝试检索它时,出现以下错误:
java.io.FileNotFoundException: \\[myip]\files\my.file (The network name cannot be found)
非常感谢。
最佳答案
尝试这两种方法将文件存储在模拟器中
- 最简单的方法就是拖放我的意思是当你 启动你的模拟器拖放你的文件,它会保存 它在你的模拟器中比你可以轻松访问它
- 您可以通过终端使用 ADB 将文件从桌面传递到模拟器。
Copy from desktop to emulator:
adb push < local > < remote >
Copy from emulator to desktop:
adb pull < remote > < local >
Here < local > is path of file / folder on your desktop and < remote> is path of file / folder on your emulator.
Here is an example:
adb push foo.txt /sdcard/foo.txt
foo.txt will be pushed (copied) to the emulator.
获取更多信息 Android Debug Bridge
关于java - 如何将文件存储在我的 Android 模拟设备上,然后从我的程序中访问它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43901291/