Hi I have a scenario where I need to convert the default Charset should be overridden bu UTF-8. I am using below class. But I am not getting the expected output. Because I use a unix system that has default UTF-8 as charset and I compare the results there. Am I wrong somewhere in this program?
public class CharsetDisplay {
public static void main(String[] args) {
System.out.println(Charset.defaultCharset().name());
System.out.println(Charset.isSupported("UTF-8"));
final Charset UTF8_CHARSET = Charset.forName("UTF-8");
try {
byte[] byteArray = new byte[] {34,34,0};
String str = new String(byteArray,UTF8_CHARSET);
System.out.println("String*** "+str);
System.out.println("String to Hex *** "+stringToHex(str));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Prints output as
windows-1252
true
String*** ""
Note after "" in the string output I have a spl char, which I don't get in a unix env