java UTF8ToGB2312
来源:互联网 发布:中国地图编辑软件 编辑:程序博客网 时间:2024/06/02 00:09
方便以后直接使用
public String UTF8ToGB2312(String str){ String utf8 = null; String gb2312 = null; String unicode = null; StringBuffer result = new StringBuffer(); try { utf8 = new String(str.getBytes( "UTF-8")); Log.d(TAG, "String utf8 =" + utf8); unicode = new String(utf8.getBytes(),"UTF-8"); Log.d(TAG, "String unicode =" + unicode); gb2312 = new String(unicode.getBytes("GB2312")); Log.d(TAG, "String gb2312 =" + gb2312); } catch(Exception e){} try { byte[] bytes = unicode.getBytes("gb2312"); int length = unicode.getBytes("gb2312").length; Log.d(TAG, "length="+length); for(int i=0; i<length; i++){ Log.d(TAG, "bytes["+i+"]="+bytes[i]); //int data = (buffer[i] >= 0) ? buffer[i] : (256+buffer[i]); String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { hex = "0" + hex; } result.append(hex.toUpperCase()); } } catch (Exception e) {} Log.d(TAG, "result.toString()="+result.toString()); return result.toString(); }
阅读全文
0 0
- java UTF8ToGB2312
- linux C++ Utf8toGb2312 Gb2312toUtf8 MyA2W和MyW2A实现
- java
- JAVA
- JAVA
- JAVA
- java
- Java
- Java
- JAVA:
- java
- java
- java
- java
- Java
- java
- java
- java
- 強制PHP
- SpringBoot之数据缓存Cache操作
- Windows下QT中用C++调用Python之二
- 投资项目经济效益敏感性分析
- 鲁班•匠心,商派第四代企业互联网商业平台发布会
- java UTF8ToGB2312
- 分享一个比较通用的Makefile
- SPI NOR 设备介绍(基于i.MX6Q平台,25VF016B型号) + SylixOS SPI总线框架
- android解决华为手机不输出log问题
- ECharts简单Demo之WEBFORM版本
- UOJ安装记录 未完待续
- Capstone训练营第二天
- IT的道德与伦理
- MySql绿色版安装及配置