java - Reading from file into Array -


I have a file with numbers It seems that the following is as follows:

  1 2 3 4 5 6 7 8 9 10  

There is a problem while reading numbers.

Here is a piece of code:

  scanner file 1 = new scanner (new file ("file1.txt")); Int lengt_h = 0; // eclipse eclipses here ... while (file1.hasNext ()) lengt_h ++; Int [] numerals = new int [lengt_h]; For (int i = 0; i & lt; numberArray.length; i ++) {numberArray [i] = file1.nextInt (); } (Int n: numberArray) System.out.print (number [n] + "");  

Even if I change the hasNext () function in a consistent length (like 10), then numbers in numbers are array like this:

 < Code> 1 1 1 2 1 1 5 5 1 3  

Why does the code not work properly?

Comments