T
terry
I find encoding and decoding of EUC_CN does not working. I have written an example:
String big5ToGB(String big5)
{
try
{
ByteArrayInputStream bais = new ByteArrayInputStream(big5.getBytes());
InputStreamReader isr = new InputStreamReader(bais,"EUC_CN");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos,"EUC_CN");
char[] cbuf=new char[80];
int n;
while((n=isr.read(cbuf))!=-1)
{
osw.write(cbuf,0,n);
}
osw.flush();
osw.close();
isr.close();
return baos.toString();
}
catch(UnsupportedEncodingException e)
{
return null;
}
catch(IOException e)
{
return null;
}
}
:
:
String s="欢迎";
debug.println(s);
String ss=ut.big5ToGB(s);
char[] c=s.toCharArray();
char[] cc=ss.toCharArray();
debug.println(c[0]);
debug.println(cc[0]);
I found the printouts are not equals.
If I change the encoding to be Big5_HKSCS, the results are matched!
Could anyone tell me how to decode Chinese GB codes correctly?
String big5ToGB(String big5)
{
try
{
ByteArrayInputStream bais = new ByteArrayInputStream(big5.getBytes());
InputStreamReader isr = new InputStreamReader(bais,"EUC_CN");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(baos,"EUC_CN");
char[] cbuf=new char[80];
int n;
while((n=isr.read(cbuf))!=-1)
{
osw.write(cbuf,0,n);
}
osw.flush();
osw.close();
isr.close();
return baos.toString();
}
catch(UnsupportedEncodingException e)
{
return null;
}
catch(IOException e)
{
return null;
}
}
:
:
String s="欢迎";
debug.println(s);
String ss=ut.big5ToGB(s);
char[] c=s.toCharArray();
char[] cc=ss.toCharArray();
debug.println(c[0]);
debug.println(cc[0]);
I found the printouts are not equals.
If I change the encoding to be Big5_HKSCS, the results are matched!
Could anyone tell me how to decode Chinese GB codes correctly?