Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the conversion between string and binary array in Java

Shulou Source: shulou.com Published: 2022-06-02 11:08:14 09月17日 Update

This article shows you how to achieve string and binary array conversion in Java, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

In the process of Java natively calling RabbitMQ, it is found that the message needs to be converted into a binary array before it can be written into the queue, while the consumer takes out the binary array into decimal ASCII code, which needs to be restored to the source value.

Public static void main (String [] args) {/ / binary array byte [] bs = "1" .getBytes (); System.out.println (bs); / / decimal ASCII code String bi = new BigInteger (bs) .toString (10); System.out.println (bi); / / restore to source value System.out.println (Character.toString ((char) Integer.parseInt (bi));}

MQ partial code

ConnectionFactory factory = new ConnectionFactory (); / / set RabbitMQ related information factory.setHost (Constant.MQ_HOST); factory.setUsername (Constant.MQ_ACCOUNT); factory.setPassword (Constant.MQ_PASSWORD); factory.setPort (Constant.MQ_PORT); / / create a new connection Connection connection = null;Channel channel = null;connection = factory.newConnection (); / / create a channel channel = connection.createChannel (); / / declare a queue channel.queueDeclare (queueName, true, false, false, null) / / send messages to the queue channel.basicPublish ("", queueName, null, message.getBytes ("UTF-8")); the above is how to convert strings and binary arrays in Java. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Binaries arrays queues characters strings content skills messages knowledge concise concise code information preface decimal that is articles more consumers articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL OPPO Reno Shulou Information NVidia