IOS和Android开发过程中,有时有写入文件操作,写入后的文件会保存在设备中,这里记录下如何获取两种平台设备的数据
IOS
ios设备文件的获取需要用到Xcode,点击Windows->Devices and Simulators
如果有设备连接,如图,选择想获取文件的设备和项目,点击Download Container即可下载。
下载后右键选择显示包内容即可查看
IOS路径获取:
NSString *audioPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"output.pcm"];
[[NSFileManager defaultManager] removeItemAtPath:audioPath error:nil];
[[NSFileManager defaultManager] createFileAtPath:audioPath contents:nil attributes:nil];
Android
Android设备可以通过android studio和abd命令行获取数据,
android studio获取文件方式:
点击工具栏中的 “View” 菜单,选择 “Tool Windows” > “Device Explorer”;
abd命令行获取文件方式:
首先安装abd,/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
验证安装,adb --version
获取文件 adb pull /storage/emulated/0/test.pcm
这里需要注意的是,如果有多个android设备(包括虚拟设备),需要进行区分。
查看设备序列号 adb devices
使用指定设备号进行序列操作 adb -s emulator-5554 pull /storage/emulated/0/test.pcm
Android路径获取:
// 获取文件路径
String filePath = getExternalFilesDir(null).getPath() +"/test.pcm";
// String filePath = Environment.getExternalStorageDirectory().getPath() + "/test.pcm";
// 输出文件路径到Logcat
Log.wtf("FilePath","PCM filePath: " + filePath);