File.listFiles() crashes for invalid UTF-8 characters

爱⌒轻易说出口 提交于 2020-02-24 05:07:25

问题


Some folder in my phone storage includes files like this:

  • dzG럫saᡑῑ.sg
  • 존Ὣ 졼).sg

So when I try to read files from this folder with File.listFiles() function my app crashes:

JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte ...... string: 'dzG럫saᡑῑ.sg'

I found out which app creates them, but it doesn't matter, for example if other users would have similar files on their phone memory, I can't just ask them to remove it

I just want to avoid app crashing

Even try...catch doesn't help (cause error with JNI/LINUX/C++):

    try {
        ... = dir.listFiles();
    } catch (RuntimeException e) {
        //
    }

So how am I supposed to solve this problem?

Same issue here File.listFiles crashes for invalid UTF-8 characters

But answer with signing apk isn't good, how is it even related to this issue? Any other solutions?

And seems debug apk is signed automatically (with debug certificate):

When running or debugging your project from the IDE, Android Studio automatically signs your APK with a debug certificate generated by the Android SDK tools. The first time you run or debug your project in Android Studio, the IDE automatically creates the debug keystore and certificate in $HOME/.android/debug.keystore, and sets the keystore and key passwords.

来源:https://stackoverflow.com/questions/47002551/file-listfiles-crashes-for-invalid-utf-8-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!