title: Read File to Process Stdin ProcessBuilder
body: <p>How do I pipe a file into the stdin of a process using ProcessBuilder?  The program I am reading the stream from is written in C, but I do not know anything else about it.</p>
  
  <p>Here is the relevant java:</p>
  
  <pre><code>  ProcessBuilder pb = new ProcessBuilder("./program").inheritIO();
    Process p = pb.start();
    DataInputStream din = new DataInputStream(new FileInputStream("./my-file.txt"));
    byte[] dinBytes = new byte[din.available()];
    din.readFully(dinBytes);
    din.close();
    OutputStream os = p.getOutputStream();
    os.write(dinBytes);
    os.close();
    int rc = p.waitFor();
    System.out.println("RC: " + rc);
  </code></pre>
  
  <p>Which returns the following error:</p>
  
  <pre><code>java.io.IOException: Stream closed
      at java.lang.ProcessBuilder$NullOutputStream.write(ProcessBuilder.java:434)
      at java.io.OutputStream.write(OutputStream.java:116)
      at java.io.OutputStream.write(OutputStream.java:75)
      at Test.main(Test.java:14)
  $ input in flex scanner failed
  </code></pre>