Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何转换Æàìáûë&引用;要在Java中读取西里尔文?_Java_Android - Fatal编程技术网

如何转换Æàìáûë&引用;要在Java中读取西里尔文?

如何转换Æàìáûë&引用;要在Java中读取西里尔文?,java,android,Java,Android,我尝试获取字节,然后使用Utf-8进行转换 byte ptext[] = first_name.getBytes(); Log.i("", new String(ptext,"UTF-8")); 但它不起作用了,对不起我的沉默。我很困惑。您的字节数组必须有一些编码。如果有负值,则编码不能为ASCII。一旦您了解了这一点,您可以使用以下方法将一组字节转换为字符串: byte[] bytes = {...} String str = new String(bytes, "UTF-8"); /

我尝试获取
字节
,然后使用Utf-8进行转换

 byte ptext[] = first_name.getBytes();
 Log.i("", new String(ptext,"UTF-8")); 

但它不起作用了,对不起我的沉默。我很困惑。

您的字节数组必须有一些编码。如果有负值,则编码不能为ASCII。一旦您了解了这一点,您可以使用以下方法将一组字节转换为字符串:

byte[] bytes = {...}
String str = new String(bytes, "UTF-8"); // for UTF-8 encoding
Log.i("value", str); 

您可以使用多种编码,请查看中的字符集类。

您的原始编码似乎是
Cp1251

byte ptext[] = first_name.getBytes();
Log.i("", new String(ptext, "Cp1251")); // <- put it here
byte ptext[]=first_name.getBytes();
Log.i(“,新字符串(ptext,“Cp1251”);//
假设编辑器和编译器设置为UTF-8,以具有正确的错误字符串文字

这将字符视为单字节,滥用ISO-8859-1。然后尝试西里尔文的Windows-1251编码(还有其他编码)。 这样我们就有了一个java字符串(总是使用Unicode)。 我们将写入一个UTF-8格式的文本文件,其中包含一个BOM表,因此Windows记事本将该文件标识为UTF-8

写入任何西里尔字母编码都不会有问题

Жамбыл

请解释你试图用这些代码实现什么。提示:把重音拉丁字符翻译成西里尔文没有多大意义。为什么不
Log.i(“,first_name))
?提示:看起来像是
Windows-1251
字节,被解释为
ISO-8859-1
。我不知道它给了我什么原始编码
java.lang.NoClassDefFoundError:java.nio.charset.StandardCharset
啊,Android转移了它的库。使用
“UTF-8”
org.apache.commons.lang3.CharEncoding.UTF\u 8
Жамбыл