Comment convertir une chaîne en octet en Java?

Comment convertir une chaîne en octet en Java?

Ici, je montre comment la variableconvert a String to a Byte avec la fonctiongetBytes() de 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);


    }
}

Sortie

Text : This is an example
Text [Byte Format] : [B@187aeca