使用默认字符集合

Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.

public byte[] getBytes()

Constructs a new String by decoding the specified array of bytes using the platform's default charset.

public String(byte bytes[])

默认字符集合

System.out.println(Charset.defaultCharset());

使用指定的字符集合

public byte[] getBytes(String charsetName)

Constructs a new String by decoding the specified array of bytes using the specified charset.

public String(byte bytes[], String charsetName)

字符集合不相同时会导致看到的字符串不一致,请确保字符集合相同。

小样:

byte[] bytes = "字符串".getBytes("utf-8");
System.out.println(new String(bytes,"utf-8"));// 字符串

String 和 byte[]的更多相关文章

  1. string转byte[]

    static byte[] GetBytes(string str) { byte[] bytes = new byte[str.Length * sizeof(char)]; System.Buff ...

  2. java String与Byte[]和String 与InputStream转换时注意编码问题。。。

    前一段日子,我在做rsa加密和通过http get方式获取验证码图片通过BitmapFactory创建bitmap 出现了一系列的问题. 通过一系列的调试,发现有些问题原来是在进行String 与By ...

  3. java中string与byte[]的转换

    1.string 转 byte[] byte[] midbytes=isoString.getBytes("UTF8"); //为UTF8编码 byte[] isoret = sr ...

  4. C# double float int string 与 byte数组 相互转化

    在做通信编程的时候,数据发送多采用串行发送方法,实际处理的时候多是以字节为单位进行处理的.在C/C++中 多字节变量与Byte进行转化时候比较方便 采用UNION即可废话少说看示例:typedef u ...

  5. java Byte.toString 方法与String.ValueOf(Byte)效率比较

    int times = 10000000; Byte[] li = new Byte[times]; for (int i = 0; i < times; i++) { li[i] = (byt ...

  6. C# String 与 byte 互转

    String转换为byte数组用byte[] arr = System.Text.Encoding.Default.GetBytes("abcde") byte数组转换为Strin ...

  7. string和byte[]的转换 (C#)

    原文 string和byte[]的转换 (C#) string类型转成byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes  ...

  8. C#中string和byte[]相互转换问题解决

    本来想讲string转换为byte数组,通过在VS上打 ‘str. “来找,结果半天没发现跳出来的函数中有想要的,哭瞎 /(ㄒoㄒ)/~~ 这回将两种情况都记下来了.... string ---> ...

  9. Go中string转[]byte的陷阱

    Go中string转[]byte的陷阱html {overflow-x: initial !important;}#write, body { height: auto; }#write, #writ ...

  10. golang string和[]byte的对比

    golang string和[]byte的对比 为啥string和[]byte类型转换需要一定的代价?为啥内置函数copy会有一种特殊情况copy(dst []byte, src string) in ...

随机推荐

  1. Android加速度传感器实现“摇一摇”,带手机振动

    由于代码有点多,所以就分开写了,注释还算详细,方便学习 Activity package com.lmw.android.test;   import android.app.Activity; im ...

  2. bzoj3551 3545

    我直接来讲在线好了 这是一个很巧妙的方法,把边作为一个点 做一遍最小生成树,当加如一条边时,我们把这条边两点x,y的并查集的根i,j的父亲都设为这条边代表的点k,由k向i,j连边 这样我们就构建出一棵 ...

  3. Liunx常用的特殊环境变量

    [weiqiang.liu@l~]$ sh variable xiaoqiang xiaoxuenumber:2scname:variablefirst:xiaoqiangsecond:xiaoxue ...

  4. UVA 11354 Bond(最小瓶颈路+倍增)

    题意:问图上任意两点(u,v)之间的路径上,所经过的最大边权最小为多少? 求最小瓶颈路,既是求最小生成树.因为要处理多组询问,所以需要用倍增加速. 先处理出最小生成树,prim的时间复杂度为O(n*n ...

  5. linux - 开机启动thunderbird、chromium

    cd ~/.config/autostart/(没有autostart,自己 mkdir autostart) vim thunderbird.desktop,输入以下: [Desktop Entry ...

  6. JavaScript备忘录-原型

    function Person() { this.name = "fs"; } Person.prototype.sayHello = function () { return & ...

  7. 本博客迁移到Github,之后停止更新

    本博客之后停止更新或者更新不是很及时,关注博客请移步   http://waylife.github.io 或者 http://blog.13kbook.com   谢谢支持. Update Time ...

  8. Drawer Layout

    http://developer.android.com/training/implementing-navigation/nav-drawer.html#DrawerLayout <menu ...

  9. redis 和 bloom filter

    今天打算使用redis 的bitset搞一个 bloom filter, 这样的好处是可以节省内存,坏处是可能在会有一些数据因为提示重复而无法保存. bloom filter 的大体原理就是通过不同的 ...

  10. Qt Style Sheets制作UI特效

    使用Qt Style Sheets制作UI特效  博客出处:http://developer.nokia.com/community/wiki/%E4%BD%BF%E7%94%A8Qt_Style_S ...