calling R script from java

后端 未结 5 1947
梦如初夏
梦如初夏 2020-12-08 05:36

I would like to call an R script from Java. I have done google searches on the topic, but almost all of the results I have seen would require me to add a dependency to some

5条回答
  •  攒了一身酷
    2020-12-08 05:54

    BufferedReader reader = null;
            Process shell = null;
            try {
                shell = Runtime.getRuntime().exec(new String[] { "/usr/bin/Rscript", "/media/subin/works/subzworks/RLanguage/config/predict.R" });
    
                reader = new BufferedReader(new InputStreamReader(shell.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);
    
                }
    
            } catch (IOException e) {
                e.printStackTrace();
            }
    

提交回复
热议问题