user924
user924

Reputation: 12245

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

Some folders in my phone storage include files like this:

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.

Upvotes: 3

Views: 507

Answers (1)

Erik
Erik

Reputation: 1

As a workaround for API>=26 you can use DirectoryStream

Upvotes: 0

Related Questions