How can I write a program that will run another Java program (that program should implement) Receive input from the program and output and print out the output in a file.
use
example:
ProcessorBuilder Pb = New process builder ("myCommand", "myArg1", "myArg2"); Process p = pb.start (); InputStream in = p.getInputStream (); Output Stream Out = p.getOutputStream (); // here on the program's input using the outputstream ... // Read the program's output from the input stream here ... ... FileOutputStream fileOut = New FileOutputStream ("output.txt"); BufferedInputStream bIn = new BufferedInputStream (in); Byte buff = new byte [4096]; integer number; 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
Comments
Post a Comment