读取服务器端的数据不需要转码。
这里有个转码的类,不知道有没有用:
import sun.io.*;
import java.io.*;public class StringConverter
{
/**
* ascii转换成中文
*/
public static String AsciiToChinese(String s)
{
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for(int i=0;i<orig.length;i++)
{
dest[i] = (byte)(orig[i]&0xFF);
}
try
{
ByteToCharConverter toChar = ByteToCharConverter.getConverter("GB2312");
return new String(toChar.convertAll(dest));
}
catch(Exception ex)
{
ex.printStackTrace();
return s;
}
}
/**
* 中文转换成ascii
*/
public static String ChineseToAscii(String s)
{
try
{
CharToByteConverter toByte = CharToByteConverter.getConverter("GB2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception ex)
{
ex.printStackTrace();
return s;
}
}
public static String EnToChinese(String s)
throws UnsupportedEncodingException
{
return new String(s.getBytes("8859_1"),"GB2312");
}
}
这里有个转码的类,不知道有没有用:
import sun.io.*;
import java.io.*;public class StringConverter
{
/**
* ascii转换成中文
*/
public static String AsciiToChinese(String s)
{
char[] orig = s.toCharArray();
byte[] dest = new byte[orig.length];
for(int i=0;i<orig.length;i++)
{
dest[i] = (byte)(orig[i]&0xFF);
}
try
{
ByteToCharConverter toChar = ByteToCharConverter.getConverter("GB2312");
return new String(toChar.convertAll(dest));
}
catch(Exception ex)
{
ex.printStackTrace();
return s;
}
}
/**
* 中文转换成ascii
*/
public static String ChineseToAscii(String s)
{
try
{
CharToByteConverter toByte = CharToByteConverter.getConverter("GB2312");
byte[] orig = toByte.convertAll(s.toCharArray());
char[] dest = new char[orig.length];
for (int i=0;i<orig.length;i++)
dest[i] = (char)(orig[i] & 0xFF);
return new String(dest);
}
catch (Exception ex)
{
ex.printStackTrace();
return s;
}
}
public static String EnToChinese(String s)
throws UnsupportedEncodingException
{
return new String(s.getBytes("8859_1"),"GB2312");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货