py4j icon indicating copy to clipboard operation
py4j copied to clipboard

UTF8 Filename error when passing parameters to Java function

Open zhengxiongzhao opened this issue 7 years ago • 2 comments

  1. Java:

OutputStream outs = new FileOutputStream(new File(filePath)); outs.write(ostream.toByteArray()); outs.close();

  1. Python:

launch_gateway(redirect_stdout=redirect_stdout javaopts=["-Dfile.encoding=UTF-8", "-Dsun.jnu.encoding=UTF-8","-Duser.language=zh","-Duser.region=CN"]

filepath = "output/abc中文.doc"

  1. Java & Python Print:

output/abc中文.doc

  1. Output File:

[root output]# locale LANG=zh_CN.UTF-8 .... LC_ALL=zh_CN.UTF-8

[root output]# ls abc??.doc

zhengxiongzhao avatar Oct 25 '18 05:10 zhengxiongzhao

Hi, we will need more details to help you:

  1. What is the Python (and possibly Java) code producing the error?
  2. What versions of Python, Java, OS are you using?

Normally, everything is encoded/decoded through UTF-8 (for examples, we had tests with accented characters), but obviously, I have little experience with this particular character set :-)

bartdag avatar Oct 25 '18 09:10 bartdag

Hi, we will need more details to help you:

  1. What is the Python (and possibly Java) code producing the error?
  2. What versions of Python, Java, OS are you using?

Normally, everything is encoded/decoded through UTF-8 (for examples, we had tests with accented characters), but obviously, I have little experience with this particular character set :-)

[xx@xx libs]# python --version Python 2.7.5 [xx@xx libs]# java -version openjdk version "1.8.0_191" OpenJDK Runtime Environment (build 1.8.0_191-b12) OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

output:abc??.doc expect:abc中文.doc

zhengxiongzhao avatar Oct 26 '18 01:10 zhengxiongzhao