I know that java 8 uses UTF-8 as standard encoding. When i read string from standard-input(System.in) with Scanner using "UTF-8" then try to print it to console and the string is not in right origin as I show beneath ,but with the initialized string the console show right original string without unexpected result.How can i fix this?Please help me!
I use Scanner not String constructor to encode input.I know how to convert input to UTF-8 but something wrong happened to my result and asked for the reason and solution to solve that problem ,not asking for the way to encode string with UTF-8.
Here is my code:
import java.nio.charset.Charset;
import java.util.Scanner;
public class charset {
public static void main(String[] args) {
System.out.println(Charset.defaultCharset());
Scanner sc =new Scanner(System.in,"UTF-8");
System.out.println(sc.nextLine());
System.out.println("á ă ấ");
}
}
-Here is my output:
run:
UTF-8
á ă ấ
� ? ?
á ă ấ
BUILD SUCCESSFUL (total time: 10 seconds)