I need user input from cmd/terminal and I want it to be encoded in UTF-8. The problem is everything i tried does not seem to work including a lot of things i found on Stackoverflow.
I tried using Scanner class with System.in as input but it didn't work:
Scanner scanIn = new Scanner(System.in, "UTF-8");
String command= scanIn.nextLine();
I should be getting ČČČ, instead i'm getting ???.
I'm aware that System.in doesn't use UTF-8, and that problem might lie there, however i could use an alternative if there is any.
package utfexample;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
public class UTFExample {
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println("Enter command: ");
Scanner scanIn = new Scanner(new InputStreamReader(System.in, "UTF-8"));
String command = scanIn.nextLine();
System.out.println("command: " + command + "\n");
if(command.equals("Č")){
System.out.println("Test was successful!");
}
}
}