简体   繁体   English

如何在java应用程序上编写UTF-8字符?

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

I want to write 我想写

ısı ISI

to csv on java netbeans. 到java netbeans上的csv。 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 但是当我清理和构建项目时,我运行.jar应用程序,然后当我看到csv时,我看到了

?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. 您使用的是系统的默认字符编码,可能是也可能不是UTF-8。 If you want to use UTF-8, you have to specify that: 如果要使用UTF-8,则必须指定:

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. 如果是这种情况,那么您将需要检查用于显示输出的任何程序(Windows命令提示符,文本编辑器或...)是否了解该文件是UTF-8并正确显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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