Android Question Spanish Characters in Filename -- FileNotFoundException

Similar threads

B4A Code Snippet [B4X] Bytes To File
B4A Code Snippet [B4X] Use WebView to show large images
B4A Code Snippet Upload files with WebView
B4A Library Printing and Pdf creation
Tool Ready to run SDK

Sterling

New Member
Licensed User
Hey all --

I'm working with retrieving data from files, some having distinctive Spanish characters or accented vowels in the filenames (e.g. enseñar.txt, marrón.txt, but also libro.txt).

Working: When I open up libro.txt, I have no issues. There are no distinctive Spanish characters or accented vowels in the filename. The file opens with no problem, and all Spanish text looks great. Again, the problem isn't the file *contents* -- I have that working when the file reads.

Not Working: When I try to open up enseñar.txt using a TextReader and File.OpenInput command, or any other filename with a distinctive Spanish character or accented vowel, I run into a FileNotFoundException (java.io.FileNotFoundException: enseñar.txt).

Any way around this, or should I come up with a standardized workaround with English filenames?

B4X:
' [ Unit Test: Filenames with ñ ]
Dim strTerm As String = "enseñar"
' Preferred Method: Load in strTerm from File
Dim strTermInfo As String = ""

Dim trSpanish As TextReader
trSpanish.Initialize2(File.OpenInput(File.DirInternal & "/terms/", strTerm.ToLowerCase & ".txt"), "iso-8859-1")
strTermInfo = trSpanish.ReadAll
trSpanish.Close
(Also a follow-up to this -- if I read values such as enseñar from a file encoded with page iso-8859-1, would I need to run a convert on it to UTF-8 in order to interface with the file system? I'm thinking it could be an encoding mismatch with the file system.)
 
Last edited:

Sterling

New Member
Licensed User
Fixed!

Ok, for a filename to interface properly, it has to be in UTF-8 encoding. In reading values from iso-8859-1 and passing that through, it's assigning special characters differently. Reading in as UTF-8 for the filename only, while reading in the contents as iso-8859-1 worked.
 
Top