Thought the above answers are write, I would like to produce the code for coming users :) The below method will accept all set of inputs(if we read more than one input for other programs) and writes them to bufferedWriter.
public static void giveInputToProcess(Process process, String[] inputs) {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
process.getOutputStream()));
for (String input : inputs) {
try {
bw.write(input);
bw.newLine();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}