-1

How can I get an input from another java program? I have one class that generates a random graph and writes it in the windows cmd console with System.out.println();. What I want is this other class to read this output and use it to do some calculations. Both classes are working fine - all I need to know is how to get this output from the first class.

EDIT: I want this http://pastebin.com/GnsUZVht to read the output that this http://pastebin.com/cgXMCbgb do to put it back in a matrix.

4

3 回答 3

2

看看这里的解决方案。

据此,您可以使用Process Builder,它用于创建操作系统进程

这个例子:

ProcessBuilder   ps=new ProcessBuilder("java.exe","-version");

ps.redirectErrorStream(true);

Process pr = ps.start();  

BufferedReader in = new BufferedReader(new 
InputStreamReader(pr.getInputStream()));
String line;

while ((line = in.readLine()) != null) {
    System.out.println(line);
}
pr.waitFor();
in.close();
System.exit(0);
于 2013-06-24T20:39:10.347 回答
0

假设您想做类似的事情(例如在 linux bash 中)

java -jar one.jar | java -jar two.jar | ...

one.jar中的代码可以写入System.out,而two.jar中的代码然后从System.in读取。

于 2013-06-24T20:47:03.943 回答
0

将两个类放在同一个程序中是最简单的,然后将第一个类生成的数据存储在一个变量中,然后将这些变量作为参数传递给下一个类,而不是从控制台打印和读取。

于 2013-06-24T20:39:25.337 回答