Java program does not print cyrillic characters, but only question marks

my code (Qwe.java)

public class Qwe {
    public static void main(String[] args) {
        System.out.println(" ");
    }
}

      

Where

test hello

- Russian words Qwe.java in UTF-8 on my machine (ubuntu 14.04) result

test hello

on server (ubuntu 12.04) I have:

??????????

$ java Qwe> test.txt in test.txt see

??????????

+3


source to share


3 answers


I'll fix it, just use export JAVA_TOOL_OPTIONS = -Dfile.encoding = UTF8



+1


source


I'm not sure, but it can only accept ASCII characters from English if you don't have some kind of extension or whatever. But as I said, my best guess is that it doesn't find characters and just dumps trash in their place.

"Java, any unknown character that is passed through the outputStream's write () methods is printed as a simple question mark"? ""



taken from here

0


source


The java source must use the same encoding as the javac compiler. It seems to be so, and UTF-8 is of course ideal.

File Qwe.class

ok, using Unicode for String. Console output uses server platform encoding. That is, java converts unicode text to bytes, using perhaps the standard (platform) encoding and cannot handle cyrillic.

So, you need to write to a file, never using FileWriter (utility class for local files only), but using:

... new OutputStreamWriter(new FileOutputStream(file), "UTF-8")

      

You can also set user locales on the server, but that's not my beer.

In general, I would switch to a file logger.

0


source







All Articles