Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: CSV file read & write
    primarykey
    data
    text
    <p>I'm reading 2 csv files: <code>store_inventory</code> &amp; <code>new_acquisitions</code>.<br> I want to be able to compare the <code>store_inventory</code> csv file with <code>new_acquisitions</code>. 1) If the item names match just update the quantity in store_inventory. 2) If new_acquisitions has a new item that does not exist in <code>store_inventory</code>, then add it to the <code>store_inventory</code>.</p> <p>Here is what i have done so far but its not very good. I added comments where i need to add taks <strong>1</strong> &amp; <strong>2</strong>.<br> Any advice or code to do the above tasks would be great! thanks.</p> <pre><code> File new_acq = new File("/src/test/new_acquisitions.csv"); Scanner acq_scan = null; try { acq_scan = new Scanner(new_acq); } catch (FileNotFoundException ex) { Logger.getLogger(mainpage.class.getName()).log(Level.SEVERE, null, ex); } String itemName; int quantity; Double cost; Double price; File store_inv = new File("/src/test/store_inventory.csv"); Scanner invscan = null; try { invscan = new Scanner(store_inv); } catch (FileNotFoundException ex) { Logger.getLogger(mainpage.class.getName()).log(Level.SEVERE, null, ex); } String itemNameInv; int quantityInv; Double costInv; Double priceInv; while (acq_scan.hasNext()) { String line = acq_scan.nextLine(); if (line.charAt(0) == '#') { continue; } String[] split = line.split(","); itemName = split[0]; quantity = Integer.parseInt(split[1]); cost = Double.parseDouble(split[2]); price = Double.parseDouble(split[3]); while(invscan.hasNext()) { String line2 = invscan.nextLine(); if (line2.charAt(0) == '#') { continue; } String[] split2 = line2.split(","); itemNameInv = split2[0]; quantityInv = Integer.parseInt(split2[1]); costInv = Double.parseDouble(split2[2]); priceInv = Double.parseDouble(split2[3]); if(itemName == itemNameInv) { //update quantity } } //add new entry into csv file } </code></pre> <p>Thanks again for any help. =]</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.
 

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