2

I'm fairly new to android and java, my background is c# .net.

I have a network share mounted to /mnt/cifs/Audio by using CifsManager. 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. I noticed that it is because there is a file or folder in that share with an invalid Modified UTF-8 name. From LogCat I can see that it is when NewStringUTF is instantiated, obviously this is done internally when I list all the files.

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.

Xtr
  • 374
  • 5
  • 12
  • I presume that `File.list()` or `File.listFiles(filter)` (with a filter skipping the file) do not work either. – Joop Eggen Jun 17 '13 at 17:40
  • File.list() results in the same issue. I have not tried the filter though. Not sure on how I could account for all the possible invalid names. – Xtr Jun 17 '13 at 17:46
  • Adding the filter does not work either.The app goes into a loop when executing file.getName() on a file that contains an invalid char in the filename. It just seems weird to me that it could break this badly when something so minor happens. And file browser apps still displays that problematic file, by substituting the invalid char. – Xtr Jun 18 '13 at 20:40
  • In Java 7 `File.list()` is called and that calls `FileSystem.list()` meaning one could install ones own FileSystem - maybe. Your best bet is to give a very detailed error report. And meanwhile capture `ls`. – Joop Eggen Jun 19 '13 at 07:09
  • Okay, it seems to only be on directories mounted from another source, like cifs or possibly USB (I have not tested USB). I think it uses the character encoding of the mounted source, so using cifs from a windows share needs to be unicode? I will do some more testing when I have time, this is a private project after all :) – Xtr Jun 23 '13 at 17:15
  • maybe some [mount](http://linux.die.net/man/8/mount) options like utf8. – Joop Eggen Jun 23 '13 at 22:48

1 Answers1

0

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. 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.

Xtr
  • 374
  • 5
  • 12