title: How to read a text file in to a scanner using command line in Java
body: <p>I have a small snippet of code that will ask user to type input such as</p>
  
  <pre><code>5
  12
  59
  58
  28
  58
  </code></pre>
  
  <p>The first number will indicate the size of the array i need to create and the rest of the numbers will be stored in that array. So with the given input an array of size 5 would be created and the numbers following would be stored in the array. </p>
  
  <p>my code</p>
  
  <pre><code>public static void main(String[] args) {
           Scanner sc = new Scanner(System.in);
           int size = sc.nextInt();
           int[] array = new int[size];
  
          for(int i =0; i&lt;size; i++)
          {
              array[i] = sc.nextInt();
          }                       
  }
  </code></pre>
  
  <p>I was wondering is there a way of just feeding a text file instead of typing numbers manually. I mean know there are ways to read text files but is there a way to just feed it in command  line. I Know in c there is some simple command where you can just type something like that and it works-> <code>./code.out &gt; input.txt</code> </p>