Note that there are some explanatory texts on larger screens.

plurals
  1. POScanner - managing input from text file
    primarykey
    data
    text
    <p>I’m working with java Scanner trying to extract product information from a text file called Inventory.txt. </p> <p>This file contains data on products in this format:</p> <pre><code>“Danelectro|Bass|D56BASS-AQUA|336177|395.00Orange|Amplifier|BT1000-H|319578|899.00Planet Waves|Superpicks|1ORD2-5|301075|4.50Korg|X50 Music Synthesizer|X50|241473|735.00Alpine|Alto Sax|AAS143|198490|795.00” </code></pre> <p>I am trying to parse the strings and add them into an arraylist such that each element in the arraylist would look something like this:</p> <pre><code>"Danelectro|Bass|D56BASS-AQUA|336177|395.00" "Orange|Amplifier|BT1000-H|319578|899.00" "KorPlanet Waves|Superpicks|1ORD2-5|301075|4.50" "g|X50 Music Synthesizer|X50|241473|735.00" "Alpine|Alto Sax|AAS143|198490|555.00” </code></pre> <p>Following is my code:</p> <pre><code>public class ItemDao { public ItemDao() { scanFile(); } public void scanFile() { Scanner scanner; ArrayList &lt;String&gt; content = new ArrayList &lt;String&gt;(); try { Pattern p1 = Pattern.compile("\\.[0-9]{2}$"); scanner = new Scanner(new File("Inventory.txt")); while (scanner.hasNext(p1)) { content.add(scanner.next(p1)); } for (String item : content) { System.out.println("Items:" + item); } } catch (FileNotFoundException e) { e.printStackTrace(); } } } </code></pre> <p>When I tested this code I found that the arraylist is empty. Any help would be much appreciated.</p> <p>java -jar A00123456Lab5.jar</p> <p>Create an ItemDAO class in a dao package This class will contain an static inner class which implements Comparator (DAO = Data Access Object)</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.
 

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