UTF-8编码下\u7528\u6237转换为中文汉字

一、前言

    有过多次,在开发项目中遇见设置文件编码格式为UTF-8,但是打开该文件出现类似\u7528这样的数据,看也看不懂,也不是平常见到的乱码。这里的\u7528类似的数据,其中'\u'表示UNICODE编码,其实数据就是对应的UTF-8下的汉字。

    此处"\u7528\u6237"表示"用户"

二、问题处理

   下面文件的编码已被设置为UTF-8,但打开这里的原文件部分内容如下:

#use 1,2
#admin_login
100001=\u7528\u6237\u540D\u6216\u8005\u5BC6\u7801\u9519\u8BEF
100002=\u7528\u6237\u540D\u6216\u8005\u5BC6\u7801\u9519\u8BEF
100003=\u7528\u6237\u6B63\u5904\u4E8E\u767B\u9646\u72B6\u6001
100004=\u672A\u77E5\u539F\u56E0,\u767B\u9646\u5931\u8D25
100088=\u767B\u9646\u6210\u529F
#use 3,4
#user_login
300001=\u7528\u6237\u540D\u6216\u8005\u5BC6\u7801\u9519\u8BEF
300002=\u7528\u6237\u540D\u6216\u8005\u5BC6\u7801\u9519\u8BEF
300003=\u7528\u6237\u5904\u4E8E\u767B\u9646\u72B6\u6001
300004=\u672A\u77E5\u539F\u56E0,\u767B\u9646\u5931\u8D25
300099=\u9000\u51FA\u6210\u529F
300088=\u767B\u9646\u6210\u529F
...

    文件截图如图2-1所示

图2-1、 '\u7528'数据的文件图

 

    这里使用开发工具是IDEA,其他工具参考设置进行修改。打开IDEA的设置,找到设置编码的页面。菜单路径是File - Settings - Editor - File Encodings。

  • (1)设置全局编码、工程编码、文件默认编码为UTF-8.
  • (2)勾选native-to-ascii
  • (3)点击按钮Apply、OK应用即可
图2-2、IDEA编码设置图

 

    设置完成后配置文件UNICODE编码转换为UTF-8,\u7528转换为对应的汉字。设置完成后效果如图2-3所示。注意如果只设置UTF-8不勾选ascii转换,则文件仍显示为\u7582格式。不能正常显示为中文。

图2-3、UTF-8编码下文件正确显示汉字图

Power By niaonao

今天在做SpringBoot 集成RabbitMQ时,启动会报 ``` java.net.SocketException: Socket Closed at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_80] at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_80] at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_80] at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ~[na:1.7.0_80] at java.io.BufferedInputStream.read(BufferedInputStream.java:254) ~[na:1.7.0_80] at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.7.0_80] at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:571) ~[amqp-client-4.0.2.jar:4.0.2] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80] 2018-12-18 18:29:21.876 INFO 10896 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection@77d0bf3e [delegate=amqp://admin@192.168.220.128:5672/, localPort= 51285] 2018-12-18 18:29:22.953 INFO 10896 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2018-12-18 18:29:22.964 INFO 10896 --- [ main] com.gg.miaosha.MainApplication : Started MainApplication in 33.034 seconds (JVM running for 34.017) 2018-12-18 18:29:27.019 WARN 10896 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:74) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:370) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:140) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:76) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:505) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1382) ~[spring-rabbit-1.7.1.RELEASE.jar:na] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80] Caused by: java.util.concurrent.TimeoutException: null at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:372) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:297) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:909) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859) ~[amqp-client-4.0.2.jar:4.0.2] at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799) ~[amqp-client-4.0.2.jar:4.0.2] at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:351) ~[spring-rabbit-1.7.1.RELEASE.jar:na] ... 7 common frames omitted ``` 以下是我的配置文件 ``` spring.rabbitmq.addresses=192.168.220.128 spring.rabbitmq.username=admin spring.rabbitmq.password=admin spring.rabbitmq.publisher-confirms=true spring.rabbitmq.virtual-host=/ spring.rabbitmq.connection-timeout=60000 #\u6D88\u8D39\u8005\u6570\u91CF spring.rabbitmq.listener.simple.concurrency= 10 spring.rabbitmq.listener.simple.max-concurrency= 10 #\u6D88\u8D39\u8005\u6BCF\u6B21\u4ECE\u961F\u5217\u83B7\u53D6\u7684\u6D88\u606F\u6570\u91CF spring.rabbitmq.listener.simple.prefetch= 1 #\u6D88\u8D39\u8005\u81EA\u52A8\u542F\u52A8 spring.rabbitmq.listener.simple.auto-startup=true #\u6D88\u8D39\u5931\u8D25\uFF0C\u81EA\u52A8\u91CD\u65B0\u5165\u961F spring.rabbitmq.listener.simple.default-requeue-rejected= true #\u542F\u7528\u53D1\u9001\u91CD\u8BD5 spring.rabbitmq.template.retry.enabled=true spring.rabbitmq.template.retry.initial-interval=1000 spring.rabbitmq.template.retry.max-attempts=3 spring.rabbitmq.template.retry.max-interval=10000 spring.rabbitmq.template.retry.multiplier=1.0 ``` 但是程序能够 正常运行 RabbitMQ也能进行正常的信息收发, 但是这个错误看着有点受不了.请问有大神知道问题出在哪里吗??
©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页