场景: 笔者在使用ADB命令推送docx文件到手机指定文件夹下,点开手机查看无异常,但使用简单的代码,程序直接闪退,起初笔者怀疑是中文路径的问题,但不是,真正的原因ADB环境不支持中文造成的。
File file = new File("文件路径");
if(file.Directory()){}//异常行
// ADB命令行操作
C:\Users\Administrator>adb push C:\Users\Administrator\Desktop\library\功能设计描述20171226.docx /storage/emulated/0/piopic/docx/功能设计描述20171226.
docx
C:\Users\Administrator\Desktop\library\功能设计æè¿°20171226.docx: 1 file pushed. 10.0 MB/s (911508 bytes in 0.087s)
//手机异常堆栈
JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0
01-09 17:33:16.498 16673-16673/com.example.readpoi A/art: art/runtime/runtime.cc:431] string: '功能设�'
01-09 17:33:16.498 16673-16673/com.example.readpoi A/art: art/runtime/runtime.cc:431] input: '0xe5 0x8a 0x9f 0xe8 0x83 0xbd 0xe8 0xae 0xbe 0xe8'
01-09 17:33:16.498 16673-16673/com.example.readpoi A/art: art/runtime/runtime.cc:431] in call to NewStringUTF
01-09 17:33:16.498 16673-16673/com.example.readpoi A/art: art/runtime/runtime.cc:431] from java.lang.String[] java.io.UnixFileSystem.list0(java.io.File)
原因:
ADB push 之后出现该BUG
解决:
https://blog.csdn.net/lixiaodaoaaa/article/details/9770405
临时解决:
电脑打开手机指定目录 直接复制粘贴文件过去