How to realize the conversion between string and binary array in Java
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.