title: Writing Multiple Lines of User Input to a File
body: <p>I am trying to have the equivalent of a text box in console by reading the user's input until a certain terminator sequence is reached, but I cannot figure out how to get it to terminate.</p>
  
  <p>Here the code that is supposed to read input and write it to the file:</p>
  
  <pre><code>try {
      out = new BufferedWriter(new FileWriter("outagain.txt");
      userInput = new Scanner(System.in);
  
      String input;
      while ((input = userInput.nextLine)) != null) {
          out.write(input);
          out.newLine();
          input = null;
      }
  } finally {
      if (userInput != null)
          userInput.close();
      if (out != null)
          out.close();
  </code></pre>
  
  <p>Is there some way I can capture an escape "code" from the user (i.e. they write ":END" which breaks out of the loop) or is there another way to do it?</p>
  
  <p>Thank you in advance.</p>