简体   繁体   中英

How can I write UTF-8 chars on java application?

I want to write

ısı

to csv on java netbeans. It works fine when I debug the code. But when I clean and build the project, I run .jar application and then when I look the csv I see

?s?

How can I solve this ?

thanks in advance.

EDIT

I use this to write :

 PrintWriter csvWriter = new PrintWriter(new File("myfile.csv")) ;              
    csvWriter.println("ısı") ;

With this code:

PrintWriter csvWriter = new PrintWriter(new File("myfile.csv")) ;              
csvWriter.println("ısı") ;

you are using the default character encoding of your system, which may or may not be UTF-8. If you want to use UTF-8, you have to specify that:

PrintWriter csvWriter = new PrintWriter(new File("myfile.csv"), "UTF-8");

Note that even if you do this, you might still see unexpected output. If that's the case, then you will need to check if whatever program you use to display the output (the Windows command prompt, or a text editor, or ...) understands that the file is in UTF-8 and displays it correctly.

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