How to edit file on console from Java?
<p>I'm trying to edit a file from CLI. I'm executing the <code>nano</code> command (I know that command will always be available); when I execute it, I can see nano's output but I cannot interact with it. How can I pass user input to the command? Do you have a better idea to easily edit a file from within my Java app?</p>

<p>This is my code:</p>

<pre><code>String command = "nano /tmp/163377867.txt ";
try {
    Process process = Runtime.getRuntime().exec(command);
    InputStream inputStream = process.getInputStream();
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

    String line;
    while ((line = bufferedReader.readLine()) != null) {
        System.out.println(line);
    }
} catch (IOException e) {
    e.printStackTrace();
}
</code></pre>
