How to convert Java String into byte[]?

后端 未结 8 1478
不知归路
不知归路 2020-11-22 16:00

Is there any way to convert Java String to a byte[] (not the boxed Byte[])?

In trying this:

System.ou         


        
8条回答
  •  情话喂你
    2020-11-22 16:18

    Try using String.getBytes(). It returns a byte[] representing string data. Example:

    String data = "sample data";
    byte[] byteData = data.getBytes();
    

提交回复
热议问题