Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Process getInputStream vs. getOutputStream

I'm a bit confused about the streams... which is which?

Simply, which stream should I use to catch the output of my Process, and which stream should I use to give my Process some input?

like image 530
Tony R Avatar asked Nov 19 '10 19:11

Tony R


1 Answers

I always ignore the names and look at what's returned. If your code has an OutputStream, you can write to it - which means it's the input for the other process. If your code has an InputStream, you can read from it - which means it's the output or error for the other process.

Fortunately, the compiler will tell you if you're doing the wrong thing - you've got the data you want to provde, so you've got to write it to the stream, which means it's got to be the OutputStream.

like image 80
Jon Skeet Avatar answered Sep 17 '22 06:09

Jon Skeet