title: java use sanner for i/o and file redirection
body: <p>I am trying to read input (from keyboard and also with command line file redirection), process the input info. and output it to a file. My understanding is that using the following code, and use command line: <code>java programName&lt; input.txt &gt;output.txt</code>we should be able to print the output to a file. But it doesn't work. Can someone please help to point out the correct way of doing this? Many thanks!</p>
  
  <pre><code>public static void main(String[] args) {
  
      Scanner sc = new Scanner (System.in);
  
      int [] array= new int[100];
      while (sc.hasNextLine()){
          String line = sc.nextLine();
  
          .....//do something
  
      }
  </code></pre>