gpt4 book ai didi

android - File.listFiles() 因无效的 UTF-8 字符而崩溃

转载 作者:行者123 更新时间:2023-12-05 07:39:37 26 4
gpt4 key购买 nike

我手机存储中的某些文件夹包含如下文件:

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

因此,当我尝试使用 File.listFiles() 函数从此文件夹读取文件时,我的应用程序崩溃了:

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

我找到了创建它们的应用程序,但这并不重要,例如,如果其他用户的手机内存中有类似的文件,我不能只要求他们删除它

我只是想避免应用崩溃

即使 try...catch 也无济于事(导致 JNI/LINUX/C++ 出错):

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

那么我该如何解决这个问题呢?

同样的问题在这里 File.listFiles crashes for invalid UTF-8 characters

但是用 signing apk 回答不好,它和这个问题有什么关系?还有其他解决方案吗?

似乎调试 apk 是自动签名的(使用调试证书):

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

最佳答案

作为 API>=26 的解决方法,您可以使用 DirectoryStream

关于android - File.listFiles() 因无效的 UTF-8 字符而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47002551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com