判断字符编码格式

/**
	 * 判断字符编码格式
	 * */
	public static void testCharset(String datastr)
	{
        try {
                String temp = new String(datastr.getBytes(), "GBK");
                Log.v("TestCharset","****** getBytes() -> GBK ******\n"+temp);
                temp = new String(datastr.getBytes("GBK"), "UTF-8");
                Log.v("TestCharset","****** GBK -> UTF-8 *******\n"+temp);
                temp = new String(datastr.getBytes("GBK"), "ISO-8859-1");
                Log.v("TestCharset","****** GBK -> ISO-8859-1 *******\n"+temp);
                temp = new String(datastr.getBytes("ISO-8859-1"), "UTF-8");
                Log.v("TestCharset","****** ISO-8859-1 -> UTF-8 *******\n"+temp);
                temp = new String(datastr.getBytes("ISO-8859-1"), "GBK");
                Log.v("TestCharset","****** ISO-8859-1 -> GBK *******\n"+temp);
                temp = new String(datastr.getBytes("UTF-8"), "GBK");
                Log.v("TestCharset","****** UTF-8 -> GBK *******\n"+temp);
                temp = new String(datastr.getBytes("UTF-8"), "ISO-8859-1");
                Log.v("TestCharset","****** UTF-8 -> ISO-8859-1 *******\n"+temp);
        }
        catch (UnsupportedEncodingException e)
        {
                e.printStackTrace();
        }
	}
 

你可能感兴趣的:(字符编码)