Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The basic idea is that you create a file reader object</p> <pre><code>FileReader fr = new FileReader('file.txt'); </code></pre> <p>and then go over the file line by line parsing each line and saving the stuff to some internal data storage (Array, HashMap).</p> <p>The while loop in the example you have does just this. The <code>FileReader</code> class will take care of the line ending for you, and will return <code>null</code> when there's no more lines to be read. What you need to do inside the while loop is to parse each line and separate the different bits of data (course name, price etc.) from each other.</p> <p><strong>EDIT:</strong> To parse the lines you would do something like the following. What is inside the while loop depends on how you format the menu files. The following works on the assumption that the menu files contains the price and the name of the course (in that order) separated by a comma on each line.</p> <pre><code>12.95$,Penne ala Arabiata 8.15$,Fish Soup </code></pre> <p>Notice that you can't use a comma in the price if you do this. You can of course use a semicolon as the separator between the data fields instead of a comma. The number of data fields is of course also up to you.</p> <pre><code>String line = ""; // read lines from file while ((line = fr.readLine()) != null) { // parse each line tokens = line.split(","); String price = tokens[0]; String courseName = tokens[1]; // extract all other information } </code></pre> <p>In your final code you'll want to save the data fields into some structure instead of just extracting them from the file. Another thing to note is that the price is a String NOT a number because of the dollar sign. Should you wish to do any calculations with the prices you'll of course need the convert it to a number with <code>parseFloat()</code> or <code>parseDouble()</code>.</p> <p>And of course if you do use the csv (comma separated values) format, it's better to go for a csv library to do the parsing for you instead of writing the parser yourself.</p> <p><a href="http://opencsv.sourceforge.net/" rel="nofollow noreferrer">http://opencsv.sourceforge.net/</a></p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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