简体   繁体   中英

How to print non-ascii character in java?

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

it comes as only one question mark in command prompt...if you know then please help me out.

Your terminal does not support UTF-8, you're most likely running Windows. Google to see how to change that.

The problem is almost certainly with the characters your default console/ide can display. Even when displayed on the screen, utf characters need a utf enabled font for them to render correctly.

There are probably Java UTF text editors on GitHub that you could use as a console replacement. Then what you need is an OutputStream that will append to the text editor panel (I created something of this ilk years ago: https://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/TextAreaOutputStream.java ) and then you need to use

System.setOut

and

System.setErr

With your Stream

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM