Creating array from file; getting error: Exception in thread "main" java.util.NoSuchElementException: No line found -


all trying create array numbers in file... i'm pretty new java may not efficient way i'm going off limited knowledge now.

when run it, following message:

exception in thread "main" java.util.nosuchelementexception: no line found @ java.util.scanner.nextline(scanner.java:1540) @ createarray.main(createarray.java:27) 

here feeble attempt @ code:

import java.io.*; import java.util.scanner; import java.util.arraylist;  public class createarray {   public static void main(string[] args) throws ioexception   {     file file = new file("numbers.txt");     scanner inputfile = new scanner(file);      // find number of lines in file     int count = 0;     while (inputfile.hasnextline())     {       string str = inputfile.nextline();       count++;     }      // create array     double[] numbers = new double[count];      // add numbers array     string str;     while (inputfile.hasnextline());     {       (int = 0; < count; i++)       {         str = inputfile.nextline();         numbers[i] = double.parsedouble(str);       }     }      // display array     (int = 0; < numbers.length; i++)       system.out.print(numbers[i] + " ");   } } 

when write inputfile.hasnextline() in code using scanner, have read line file.
@tima said, completed reading file in first while loop. try looking @ java: read txt file array


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -