zoukankan      html  css  js  c++  java
  • Java调用执行python脚本

      public static void main(String[] args) throws IOException, InterruptedException {
    		String[] para=new String[] {"python","C:\Users\asus\Desktop\java_invoked.py"};
            PythonInvoke.invokePy(para);
    	}
    	
    	
    	/**
         * java项目调用python脚本 
         */
        public static void invokePy(String[] para) {
            System.out.println("执行....");
            try {
            	Process process = Runtime.getRuntime().exec(para);
            	
            	BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
            	
            	String line = null;
            	while((line = reader.readLine()) != null) {
            		System.out.println(line);
            	}
            	reader.close();
            	process.destroy();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("结束....");
        }
    

      

  • 相关阅读:
    《入门经典》——6.25
    《入门经典》——6.24
    hdu4417
    poj2104(划分树模板)
    D. 实验室传染病
    poj2069
    poj1379
    hdu5950
    poj3417
    LCA——求解最近公共祖先
  • 原文地址:https://www.cnblogs.com/MT-1996/p/12988658.html
Copyright © 2011-2022 走看看