java 调用 python 中文乱码

Runtime.getRuntime().exec

当被调用的节本有中文输出的时候,还是乱码!!!因为Python安装在Windows环境下的默认编码格式是GBK!!!

我的解决办法:在被调用的脚本中增加如下代码

import io
import sys
 
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

猜你喜欢

转载自www.cnblogs.com/whm-blog/p/12914832.html