1

my program doesn't work with these symbols like ą,č,ę,ė,€ and etc. What should I write on this code that it started to work with all the symbols? I can`t find it out with similar topics in Forum. Could someone give me a tip?

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Unicode {

public static void main(String[] args) {

InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

try {

  String line = null;
  while ((line = bufferedReader.readLine()).length() > 0) {
    for (int index = 0; index < line.length(); index++) {

      String hexCode = Integer.toHexString(line.codePointAt(index)).toUpperCase();

      String hexCodeWithAllLeadingZeros = "0000" + hexCode;
      String hexCodeWithLeadingZeros = hexCodeWithAllLeadingZeros.substring(hexCodeWithAllLeadingZeros.length()-4);
      String a = "U+" + hexCodeWithLeadingZeros;

      System.out.println("Unicode: "+a);

      String b = line;
        byte[] xxx = b.getBytes("UTF-8");

        for (byte x : xxx) {
        System.out.print(Integer.toHexString(x & 0xFF).toUpperCase()+" ");
        }

      System.out.println();
      System.out.println();
    }

  }
} catch (IOException ioException) {
       ioException.printStackTrace();
  }
 }
}

It gives me this: Unicode: U+FFFD EF BF BD

  • 1
    Possible duplicate of [Encode String to UTF-8](http://stackoverflow.com/questions/5729806/encode-string-to-utf-8) – Nir Alfasi Jan 30 '17 at 21:05
  • Actually this place is not working as I want: `String b = line; byte[] y = b.getBytes("UTF-8"); for (byte x : y) { System.out.print(Integer.toHexString(x & 0xFF).toUpperCase()); }` – Arnas Arnelis Jan 31 '17 at 09:14

0 Answers0