简体   繁体   English

Android中File.listFiles()中编码问题的错误处理

[英]Error handling for encoding problems in File.listFiles() in android

I'm fairly new to android and java, my background is c# .net. 我对android和java相当陌生,我的背景是c#.net。

I have a network share mounted to /mnt/cifs/Audio by using CifsManager. 我使用CifsManager将网络共享安装到/ mnt / cifs / Audio。 Other apps on the device can display the files in that directory. 设备上的其他应用程序可以显示该目录中的文件。

My problem is that my app goes into a loop when calling listFiles() on a File object. 我的问题是,在File对象上调用listFiles()时,我的应用程序进入了循环。 I noticed that it is because there is a file or folder in that share with an invalid Modified UTF-8 name. 我注意到这是因为该共享中有一个文件或文件夹带有无效的Modified UTF-8名称。 From LogCat I can see that it is when NewStringUTF is instantiated, obviously this is done internally when I list all the files. 从LogCat中,我可以看到是实例化NewStringUTF的时间,显然,这是在列出所有文件时在内部完成的。

How can I get around this issue? 我该如何解决这个问题? Is there a way to handle that error/exception or is there another way to get all the files & folders without running into this issue? 有没有一种方法可以解决该错误/异常,或者有另一种方法来获取所有文件和文件夹而不会遇到此问题?

Any help would be greatly appreciated. 任何帮助将不胜感激。

Not really the answer to my question, but it does allow me to do what I intended. 并不是我的问题的真正答案,但是它确实允许我按照自己的意愿去做。

I am now using the JCIFS library to handle all the mounting and so forth. 我现在正在使用JCIFS库来处理所有安装等。 This library then handles the encoding internally and with good results. 然后,该库在内部处理编码,效果良好。

It seems to skip those file/directory names that it doesn't recognize and thus provides some form of error handling on the file/directory names. 似乎跳过了无法识别的文件/目录名称,因此对文件/目录名称提供了某种形式的错误处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM