数据是这样的"\314\251\270",得到就是这样的了,要把这个转换成汉字字符串
1条回答 默认 最新
- threenewbee 2018-11-26 12:07关注
import java.io.UnsupportedEncodingException; public class HelloWorld { public static String toOct(String s) { String result = ""; byte[] bytes = s.getBytes(); for (byte b : bytes) { int b1 = b; if (b1 < 0) b1 = 256 + b1; result += "\\" + (b1 / 64) % 8 + "" + (b1 / 8) % 8 + "" + b1 % 8; } return result; } public static String getOct(String s) throws UnsupportedEncodingException { String[] as = s.split("\\\\"); byte[] arr = new byte[as.length - 1]; for (int i = 1; i < as.length; i++) { int sum = 0; int base = 64; for (char c : as[i].toCharArray()) { sum += base * ((int)c - '0'); base /= 8; } if (sum >= 128) sum = sum - 256; arr[i - 1] = (byte)sum; } return new String(arr,"UTF-8"); //如果还有乱码,这里编码方式你可以修改下,比如试试看unicode gbk等等 } public static void main(String[] args) throws java.io.UnsupportedEncodingException { String s = "123中文"; String o = toOct(s); System.out.println(o); s = getOct(o); System.out.println(s); } }
\061\062\063\344\270\255\346\226\207
123中文本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 2
悬赏问题
- ¥15 利用加权最小二乘法求亚马逊各类商品的价格指标?怎么求?
- ¥15 c++ word自动化,为什么可用接口是空的?
- ¥15 Matlab计算100000*100000的矩阵运算问题:
- ¥50 VB6.0如何识别粘连的不规则的数字图片验证码
- ¥16 需要完整的这份订单所有的代码,可以加钱
- ¥30 写一个带界面控制的机房电脑一键开机关机并且实时监控的软件
- ¥15 Stata数据分析请教
- ¥15 请教如何为VS2022搭建 Debug|win32的openCV环境?
- ¥15 关于#c++#的问题:c++如何使用websocketpp实现websocket接口调用,求示例代码和相关资料
- ¥15 51单片机的外部中断,按下按键后不能切换到另一个模式