数据是这样的"\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
悬赏问题
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!