Javaで文字列をバイトに変換する方法は?
ここでは、StringのgetBytes()関数を使用してconvert a String to a Byte変数を実行する方法を示します。
public class TestByte { public static void main(String[] argv) { String example = "This is an example"; byte[] bytes = example.getBytes(); System.out.println("Text : " + example); System.out.println("Text [Byte Format] : " + bytes); } }
出力
Text : This is an example Text [Byte Format] : [B@187aeca