Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过控制台将unicode字符从python传递到Java_Java_Python_Unicode - Fatal编程技术网

通过控制台将unicode字符从python传递到Java

通过控制台将unicode字符从python传递到Java,java,python,unicode,Java,Python,Unicode,我目前正在开发一个与unicode字符相关的应用程序 因为在传递给Java进行处理之前,必须在python中读取unicode字符以确定语言。但是,目前我正在阅读该文件,首先使用python确定语言,然后调用相应的Java引擎对其进行处理 由于涉及太多的I/O成本,此方法花费的时间太长,但直接将unicode字符作为参数传递不起作用,它会引发错误: 'charmap' codec cant encode characters in position xx - xx: character maps

我目前正在开发一个与unicode字符相关的应用程序

因为在传递给Java进行处理之前,必须在python中读取unicode字符以确定语言。但是,目前我正在阅读该文件,首先使用python确定语言,然后调用相应的Java引擎对其进行处理

由于涉及太多的I/O成本,此方法花费的时间太长,但直接将unicode字符作为参数传递不起作用,它会引发错误:

'charmap' codec cant encode characters in position xx - xx: character maps to <undefined>. 
Java处理它并将其写入文件

目前,

#determines what is the language. 
filepath = "filepath of text file"
command = "java -jar unicodeProcessor.jar " + filepath
subprocess.Popen(command, stdout = PIPE, stderr = PIPE)
#in this method I am taking the parameter to be a file instead of a string 
这个方法太慢了

当前代码:

unic = open("unicode_words.txt")
words = unic.read()
if ininstance(words, str):
    convert = unicode(words, 'utf-8')
else: 
    convert = words

command = "java -jar unicodeProcessor.jar " + convert
subprocess.Popen(command, stdout = PIPE, stderr = PIPE)

你的问题是什么?解释“不工作”。@Lutz Horn更新了我的问题,那么您的Java应用程序需要什么编解码器?您不能只向其写入Unicode字符串;隐式编码失败。在哪里使用
charmap
?向我们展示给出此错误的输入和抛出此错误的代码。@MartijnPieters您所说的错误是什么意思。我可以用utf-8编码。但在我把它们交给stdout之前。我已经把它们转换成utf-8了。
unic = open("unicode_words.txt")
words = unic.read()
if ininstance(words, str):
    convert = unicode(words, 'utf-8')
else: 
    convert = words

command = "java -jar unicodeProcessor.jar " + convert
subprocess.Popen(command, stdout = PIPE, stderr = PIPE)