Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report