Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Scanner not recognizing lines in file
    primarykey
    data
    text
    <p>So I am using the following to read in a text file:</p> <pre><code>import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; String f = "file.txt"; Scanner in = new Scanner(new File(f)); while(in.hasNextLine()){ //code here to make a matrix from the data in the text file } </code></pre> <p>now this text file should create a matrix with 48927 rows (the number of lines in the text file). At the 196th row, the while loop breaks.</p> <p>It used to be the 198th row, then I stripped white space (not the ending line break) and it moved to 196</p> <p>I looked at both of these rows, and there is nothing differing them from the others!</p> <p><strong>Why is scanner not reading them as lines?</strong></p> <h1>rows</h1> <p>just to give you some inside on the file, here are what the rows look like (195-200):</p> <pre><code>CRUMBS BAKE SHOP&lt;split&gt;420&lt;split&gt;LEXINGTON AVENUE&lt;split&gt;10017&lt;split&gt;2122970500&lt;split&gt;2010-12-30 00:00:00&lt;split&gt;10.0&lt;split&gt;N&lt;split&gt;MANHATTAN&lt;split&gt;BAKERY FAITHY'S KITCHEN&lt;split&gt;3907&lt;split&gt;DYRE AVENUE&lt;split&gt;10466&lt;split&gt;7186550780&lt;split&gt;2010-12-03 00:00:00&lt;split&gt;22.0&lt;split&gt;N&lt;split&gt;THE BRONX&lt;split&gt;CARIBBEAN SIRUYEON&lt;split&gt;150-36&lt;split&gt;NORTHERN BOULEVARD&lt;split&gt;11354&lt;split&gt;7184616677&lt;split&gt;2013-05-07 00:00:00&lt;split&gt;60.0&lt;split&gt;N&lt;split&gt;QUEENS&lt;split&gt;CAFE, COFFEE, TEA MILON BANGLASESH &amp; INDIAN RESTAURANT&lt;split&gt;93&lt;split&gt;1 AVENUE&lt;split&gt;10003&lt;split&gt;2122284896&lt;split&gt;2013-02-20 00:00:00&lt;split&gt;19.0&lt;split&gt;B&lt;split&gt;BROOKLYN&lt;split&gt;BANGLADESHI HOLEY CREAM&lt;split&gt;796&lt;split&gt;9 AVENUE&lt;split&gt;10019&lt;split&gt;2122478400&lt;split&gt;2011-07-18 00:00:00&lt;split&gt;16.0&lt;split&gt;B&lt;split&gt;MANHATTAN&lt;split&gt;ICE CREAM, GELATO, YOGURT, ICES CHOP'T&lt;split&gt;1460&lt;split&gt;BROADWAY&lt;split&gt;10036&lt;split&gt;6465710601&lt;split&gt;2011-10-25 00:00:00&lt;split&gt;nan&lt;split&gt;A&lt;split&gt;MANHATTAN&lt;split&gt;SALADS </code></pre> <p>note: the commas in the last row is a common feature throughout the entire text file</p> <h1>error</h1> <p>if I let the while loop go until an error, at line 196 (the line it cannot recognize) I get this error:</p> <pre><code>Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1516) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload