title: Writing ints to a file and reading them, hasNext() return false
body: <p>I have to write 100 random integers to a file, and display them in increasing order. PrintWriter writes them, but when I try to read from file, method <code>hasNext()</code> return false, and I can't understand why. I suppose the problem is with PrintWriter.</p>
  
  <pre><code>try(PrintWriter output = new PrintWriter(file);
                  Scanner input = new Scanner(file)) {
  
              for (int i = 0; i &lt; 100; i++) {
                  output.print((int)(Math.random() * 101) + " ");
              }
  
              int[] numbers = new int[100];
              int i = 0;
              while (input.hasNextInt()) {
                  numbers[i++] = input.nextInt();
              }
  
              Arrays.sort(numbers);
              for (int n : numbers)
                  System.out.println(n);
  
          } catch (FileNotFoundException ex) {
              System.out.println("Cannot find the file!");
          }
  </code></pre>