简体   繁体   English

用扫描仪读取的输入,然后打印显示不同的字符

[英]Input read with Scanner and then printed shows different characters

I am experiencing a problem with Java's Scanner class. 我遇到了Java的Scanner类的问题。 When i input a certain sequence of characters i get an even crazier one back with no alterations whatsoever. 当我输入某个特定的字符序列时,我会得到一个甚至更疯狂的字符,并且没有任何变化。 For example using the code: 例如,使用代码:


public static void main(String args[]){
   Scanner input = new Scanner(System.in);
   System.out.println("Begin");
   String foo = input.nextLine();
   System.out.println(foo);
}

If i input the string %ʒʼnÛ I will get the output string %Ê'ʼnÛ When i am doing absolutely zero alterations to the actual string. 如果我输入字符串%ʒʼnÛ我将得到输出字符串%Ê'ʼnÛ当我对实际字符串进行绝对零更改时。 Can someone help me find a way to avoid this? 有人可以帮我找到避免这种情况的方法吗? (BTW avoiding the set of characters %ʒʼnÛ is very unlikely because its part of an encoding process. (顺便说一句,避免字符集%ʒʼnÛ的可能性很小,因为它是编码过程的一部分。

尝试指定字符集:

Scanner input = new Scanner(System.in, "UTF-8");

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

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