/* files for testcase:
printf '\xE0' >> `printf sbcs-'\xE0'`.html
printf '\xC3\xA0' >> `printf utf-'\xC3\xA0'`.html
*/
File dir = new File ("/tmp/m5");
File[] files = dir.listFiles ();
Boolean ok = true;
for (int i = 0; i < files.length; ++i) {
try{
RandomAccessFile raf = new RandomAccessFile (files[i], "r");
...
Assuming no changes to the filesystem and no permissions issues, When can the RandomAccessFile throw a File Not Found exception?
There is no guarantee about the character set used in a unix filename — it could be from any single byte codpage, and it could be from something like UTF-8 — this would depend on the value of the LANG variable at the time the file was created, and the tool that created it.
If your current locale is UTF-8, and the filename is really encoded with some single byte character set, and theres a sequence that can’t be interpreted as UTF-8, the File Not Found will be thrown.
If your current locale is a 7-bit character set (LANG=C, LANG=POSIX, LANG=US-ASCII, or any LANG setting your /etc/locale.gen hasn’t generated) and the filename has 8-bit charactes in it, the File Not Found will be thrown.
These are both a symptom of some implicit conversion of the bytestream comprising the filename into a String in the “current” locale — a conversion rarely of any value.
As Bill Oreilly says… show me where I’m wrong