G
gk
what is platform's default charset ?
String original = new String("A" + "\u00ea" + "\u00f1" +
"\u00fc" + "C");
try {
byte[] utf8Bytes = original.getBytes("UTF8");
byte[] defaultBytes = original.getBytes();
String roundTrip = new String(utf8Bytes, "UTF8");
String defaultTrip = new String(defaultBytes);
System.out.println("roundTrip = " + roundTrip); // output-1
System.out.println("defaultTrip = " + defaultTrip); // output-2
QUESTION :
why output-1 and output-2 are same ?
REASON OF THIS QUESTION :
String original = new String("A" + "\u00ea" + "\u00f1" +
"\u00fc" + "C");
this is a unicode string and it looks like "AêñüC"
How could the second output output-2 produces the same output as
output-1 ?
the ouput-2 has been encoded/decoded into "platform's default charset"
.. as i have used
byte[] defaultBytes = original.getBytes();
and
String defaultTrip = new String(defaultBytes);
for the output-2
(My System is windows XP ) ......so how that could produce the same
output as output-1 which uses encoding UTF-8 ?
do yo want to say, windows XP supporting UTF-8 ? so, by default it
picks up the UTF-8 encoding ?
in which place this 2 output i.e output-1 and output-2 wnt be same ?
is it in linux ? solaris ?
or where this two output are not same .
thank you
String original = new String("A" + "\u00ea" + "\u00f1" +
"\u00fc" + "C");
try {
byte[] utf8Bytes = original.getBytes("UTF8");
byte[] defaultBytes = original.getBytes();
String roundTrip = new String(utf8Bytes, "UTF8");
String defaultTrip = new String(defaultBytes);
System.out.println("roundTrip = " + roundTrip); // output-1
System.out.println("defaultTrip = " + defaultTrip); // output-2
QUESTION :
why output-1 and output-2 are same ?
REASON OF THIS QUESTION :
String original = new String("A" + "\u00ea" + "\u00f1" +
"\u00fc" + "C");
this is a unicode string and it looks like "AêñüC"
How could the second output output-2 produces the same output as
output-1 ?
the ouput-2 has been encoded/decoded into "platform's default charset"
.. as i have used
byte[] defaultBytes = original.getBytes();
and
String defaultTrip = new String(defaultBytes);
for the output-2
(My System is windows XP ) ......so how that could produce the same
output as output-1 which uses encoding UTF-8 ?
do yo want to say, windows XP supporting UTF-8 ? so, by default it
picks up the UTF-8 encoding ?
in which place this 2 output i.e output-1 and output-2 wnt be same ?
is it in linux ? solaris ?
or where this two output are not same .
thank you