Reputation: 5335
Using Java: I am reading a directory containing files with Greek Names. But when i output a String containing a file name i get this '???????.something'.
Is it because i am running the java app. through the console?
Is there a way to get non-latin file names read correctly?
Thanks,
Upvotes: 0
Views: 1414
Reputation: 1499860
To add to what simonn wrote, it's worth writing out the Unicode code points with something like this:
public static void dumpString(String text)
{
for (int i=0; i < text.length(); i++)
{
char c = text.charAt(i);
System.out.printf("%c U+%04x", c, (int) c);
System.out.println();
}
}
You can then look at the Unicode web site to find out what those characters really mean. (The Code Charts page is very handy.)
Upvotes: 0
Reputation: 6269
change your console to use utf-8 as char encoding - that should fix that issue
Upvotes: 1
Reputation: 43159
It could well be reading in the file names correctly; the most likely explanation is that your console can't render non-Latin characters.
For example, the following program is supposed to print out the first three letters of the Greek alphabet:
public class AlphaBetaGamma
{
public static void main(String[] args)
{
String abc = "\u03b1\u03b2\u03b3";
System.out.println(abc);
}
}
It prints out "???" on my Console, because it's not capable of rendering the Greek characters.
Upvotes: 2