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')

 

posted @ 2020-05-19 08:53  whmmm  阅读(1266)  评论(0)    收藏  举报
//增加一段JS脚本,为目录生成使用