Как преобразовать строку в байт в Java?
Здесь я демонстрирую, как использовать переменнуюconvert a String to a Byte с функциейgetBytes() String.
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