java程序跑在windows下远程接口中文乱码问题修复

公司有个需求,将现有的单体java程序用linux迁移到windows上运行(节约磁盘空间),单体程序有从多个远程接口获取数据,在linux下运行没任何问题,结果一到windows下运行,从远程获取的数据就会出现中文乱码问题。

2022-04-21 17:19:39 [ DefaultQuartzScheduler_Worker-4:15535 ] - [ INFO ] result -> {"code":200,"message":"","desc":null,"data":{"salesOfficeId":"bac49e24-a734-476d-8184-5f1bebfad183","salesOfficeName":"鍦h姯鑺媺","deviceIp":"192.168.80.110","name":"椹北鍦e洯鎽勫儚澶?,"location":"椹北鍦e洯娌欑洏杩囬亾","remark":null,"deviceSn":"011","direction":0,"status":1,"onlineStatus":0,"createTime":"2022-04-12 10:30:05"}}

将乱码copy到以下网站

乱码恢复

可以还原出中文

可见,中文版的windows系统,默认是gbk编码,而我们的程序是UTF-8,

程序里面进行编码转换即可

logger.info("GBK to UTF-8 -> "+new String(info.getName().getBytes("GBK"),"UTF-8"));

你可能感兴趣的:(code,java)