Re: reading filenames from stdin - with umlauts?
- From: John W Kennedy <jwkenne@xxxxxxxxxxxxx>
- Date: Mon, 28 Jul 2008 20:17:19 -0400
Dan Stromberg wrote:
However, to my disappointment, the java version of the program can't seem to deal with filenames that have umlauts in them. Filenames using only characters in the English alphabet seem fine.
I suspect the problem is that the file_name_, as it appears in a Linux ext3 filesystem, has an 8 bit per character representation, but java wants to convert the string I read from stdin to a 16 bit per character representation, and then doesn't reverse the conversion when I go to open the file by its name.
No. Java /always/ uses 16-bit characters; if it did that, it couldn't open files at all.
Try running this program:
import java.io.File;
public final class DirScan {
public static void main(final String[] args) {
for (final String dirName : args) {
System.out.println(dirName);
final File dir = new File(dirName);
final File[] files = dir.listFiles();
for (final File file : files) {
final String fileName = file.toString();
System.out.printf(" %-25s ", fileName);
for (int i = 0; i < fileName.length(); ++i)
System.out.printf(" %04X", (int) fileName.charAt(i));
System.out.println();
}
}
}
}
....specifying one or more directories as arguments.
--
John W. Kennedy
"Never try to take over the international economy based on a radical feminist agenda if you're not sure your leader isn't a transvestite."
-- David Misch: "She-Spies", "While You Were Out"
.
- Prev by Date: Re: Logarithms in Java BigInteger
- Next by Date: Re: Logarithms in Java BigInteger
- Previous by thread: Re: reading filenames from stdin - with umlauts?
- Next by thread: Re: java 5 and PBEWithSHA1AndAES
- Index(es):
Relevant Pages
|