java inputstream 传递给 py 处理

java  inputstream 传递给 py 处理


/**
 * @author baoyou E-mail:[email protected]
 * @version 2016年8月1日 下午1:05:36
 *<pre>
 <dependency>
    <groupId>jython</groupId>
    <artifactId>jython</artifactId>
    <version>2.1</version>
 </dependency>
 *</pre>
 * desc: ...
 */
public class PythonByJavaInputStream {

    public static void main(String[] args) throws FileNotFoundException {

        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("I:\\cache\\ea-ws\\DemoJava\\conf\\pystream.py");
        PyFunction func = (PyFunction) interpreter.get("processFile", PyFunction.class);
        File file = new File("I:\\cache\\ea-ws\\DemoJava\\conf\\1.txt");
        InputStream in = new FileInputStream(file);
        func.__call__(new PyFile(in));
    }

}

  


 

#!/usr/bin/python3
# -*- coding: UTF-8 -*- 
'''
Created on 2017年5月24日

@author: hadoop
'''
def process(filepath):
     file = open(filepath, 'r')
     processFile(file)
      
def processFile(file):
     print "===================="
     lines= file.readlines()
     for line in lines:
        print line
     file.close()
     print "===================="

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信捐助,加入it技术扣扣群),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

猜你喜欢

转载自knight-black-bob.iteye.com/blog/2376170
今日推荐