3
다른 Java 프로그램 (이 프로그램을 호출해야 함)을 실행하는 프로그램을 작성하여이 프로그램에서 해당 프로그램에 대한 입력을 제공하고 출력을 가져 와서 파일로 출력.소스에서 Java 프로그램 입출력을 얻고 얻으십시오
다른 Java 프로그램 (이 프로그램을 호출해야 함)을 실행하는 프로그램을 작성하여이 프로그램에서 해당 프로그램에 대한 입력을 제공하고 출력을 가져 와서 파일로 출력.소스에서 Java 프로그램 입출력을 얻고 얻으십시오
예 : 내가 전에 ProcessBuilder를 클래스에 들어하지 않았다
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Process p = pb.start();
InputStream in = p.getInputStream();
OutputStream out = p.getOutputStream();
// Write to input of the program using outputstream here
...
// Read output of program from input stream here
// ...
FileOutputStream fileOut = new FileOutputStream("output.txt");
BufferedInputStream bIn = new BufferedInputStream(in);
byte buf = new byte[4096];
int count;
while ((count = bIn.read(buf)) != -1) {
fileOut.write(buf, 0, count);
}
...
fileOut.close();
bIn.close();
// Exception handling is left as an exercise for the reader :-P
. 팁 고마워! –