file - Java while(input.hasnextline) loop not exiting? -


so i'm supposed determine number of lines in text file (a 100 lines containg numbers) , create array the number of lines, first while loop used find out number of lines in text file never exits. second loop exacts same 1 works fine. please me out!

static void main(string[] args) throws exception{     java.io.file file = new java.io.file("seriesofnumbers.txt"); //file instance                     scanner input = new scanner(file); //scanner     int m =0 ;     while (input.hasnextline() && !input.equals(null))// ** loop never exits, tried     {         k++;     }     double[] numberarray = new double[k];     int v = 0;     while (input.hasnextline())// when exit first loop 1 exits fine     {         numberarray[j] = (double) input.nextint();         j++;     }                

you never consuming input in first loop, input.nextline().

you looping until input.hasnextline() becomes false, never happens, because not consume input.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -