java - Reading double values from a file -


I am trying to read some numbers (double) from a file and store them in an array and an array (Yes, I need both) with the code below:

  try {scanner scan = new scanner (file) .useDelimiter ("\\ s * \" \ N "); While (scan.hasNextDouble ()) {tmp.add (scan.nextDouble ()); } Double [] [] tmp2 = new double [tmp.size () / 2] [2]; Int tmp3 = 0; For (int i = 0; i & lt; tmp.size () / 2; i ++) {for (int j = 0; j and lt; 2; j ++) {tmp2 [i] [j] = Tmp.get (tmp3); Tmp3 ++; }}} Hold (FileNotFoundException e1) {e1.printStackTrace (); }  

}

The file I am trying to read is:

  0.0 0.0 0.023 0.023 0.05 0.05 0.2 0.2 0.5 0.5 0.8 0.8 0.950 0.950 0.977 0.977 1.0 1.0  

But my code does not work, hasNextDouble () function is not getting anything, what am I doing wrong ?

Edit: OK, I edited the source slightly (changing the object from [] [] to [] []) and after adding it into the array added to the array, but it still works Does not - 'while' loop is not executed at the same time.

I tried to reduce the code only to check the scanner myself The following code with your data file Works:

  public static zero main (string [] args) {scanner scan; File file = new file ("resource \\ scannerster \\ data.txt"); {Scan = try new scanner (file); While (scan.hasNextDouble ()) {System.out.println (scan.nextDouble ()); }} Hold (FileNotFoundException e1) {e1.printStackTrace (); }}  

I found the following (expected) output:

  0.0 0.0 0.02 0.023 0.05 0.05 0.2 0.2 0.5 0.5 0.8 0.8 0.95 0.95 0.977 0.977 1.0 1.0 < / Code> 

Try to make sure that you are referencing the correct file.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -