title: External program from our Java program
body: <p>How can I write a program in Java that will execute another program? Also, the input of that program should be given from our program and the output of that program should be written into a file.</p>
  
  <p>This is my small set of code to get its output:</p>
  
  <pre><code>Process p = Runtime.getRuntime().exec("C:\\j2sdk1.4.0\bin\\helloworld.java");
  BufferedReader input =
          new BufferedReader(new InputStreamReader(p.getInputStream()));
  while ((line = input.readLine()) != null) 
    System.out.println(line);
  
  input.close();
  </code></pre>
  
  <p>This was my set of code but this throws an <code>IOException</code>. </p>