简体   繁体   English

Java将字符串编码为cp1251

[英]Java encoding String to cp1251

I have project in 'windows-1251' encoding. 我有“ windows-1251”编码的项目。 And next code print me 'P©' instead 'Щ': 接下来的代码将我打印为“ P©”而不是“Щ”:

  String var = "Щ";
  Println(var);

I try to convert this String in byte[] format and get different results but there are not correctly. 我尝试将此String转换为byte []格式,并得到不同的结果,但是没有正确显示。 How can I print my primary symbol? 如何打印我的主要符号?

You need to specify source encoding. 您需要指定源编码。 In maven you do this like : 在Maven中,您可以这样

<project.build.sourceEncoding>CP-1251</project.build.sourceEncoding>

But it's generally bad idea to use anything other than UTF-8 nowadays... 但是现在使用UTF-8以外的任何东西通常是个坏主意...

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

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